home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / utils / crossword / source / crossword.s < prev    next >
Encoding:
Text File  |  1980-01-04  |  72.1 KB  |  3,424 lines

  1.  
  2.  
  3.  
  4. * CROSSWORD.S - complete crossword designing/solving tool
  5.  
  6. * Version    : 1.20
  7.  
  8. * Revision    : 3.94
  9.  
  10. * Details:
  11.  
  12. * Program called either using the CLI command "crossword" or by
  13. * double-clicking upon WorkBench icon. Program takes no input
  14. * parameters. Access to disc files is via an extended disc access
  15. * requester (which will handle ALL disc functions required).
  16.  
  17. * Requesters available for all manner of special application
  18. * functions, including clue editing and selection, solution
  19. * entry and removal, and grid manipulation (except those that
  20. * are handled via menu selection). Requesters have a standard
  21. * format.
  22.  
  23. * NOTE : the graphical user interface is entirely my own devising,
  24. * and is intended to be both easy to understand and visually exci-
  25. * ting. A lot of effort has gone into this, so don't knock it!
  26.  
  27. * Version 1.2 will have better gadget handling!
  28.  
  29.  
  30.         include    SOURCE2:INCLUDES/my_exec.i
  31.         include    SOURCE2:INCLUDES/my_dos.i
  32.         include    SOURCE2:INCLUDES/my_intuition.i
  33.         include    SOURCE2:INCLUDES/my_graf.i
  34.  
  35.  
  36. * Equates
  37.  
  38. RawKeyConvert    equ    -48
  39.  
  40. MEMF_VARS    equ    MEMF_PUBLIC+MEMF_CLEAR
  41.  
  42. FALSE        equ    0
  43. TRUE        equ    -1
  44.  
  45. RastPort        equ    50
  46. UserPort        equ    86
  47.  
  48. ON_MENU        equ    8
  49.  
  50. SQ_X        equ    10
  51. SQ_Y        equ    10
  52.  
  53. MAXSQ_X        equ    50    ;max no of allowed squares
  54. MAXSQ_Y        equ    50    ;in grid in both directions
  55.  
  56. MINSQ_X        equ    3    ;min values of above
  57. MINSQ_Y        equ    3
  58.  
  59. GRID_BX        equ    SQ_X*MAXSQ_X+4
  60. GRID_BY        equ    SQ_Y*MAXSQ_Y+4
  61.  
  62. GRID_LEFT    equ    10
  63. GRID_UP        equ    16
  64.  
  65. MAX_DISPX    equ    15
  66. MAX_DISPY    equ    15
  67.  
  68. MAX_DISP_PX    equ    MAX_DISPX*SQ_X+4
  69. MAX_DISP_PY    equ    MAX_DISPY*SQ_Y+4
  70.  
  71. MAXCTLEN        equ    20        ;max chars per line of clue
  72.  
  73. HANG1        equ    $10000        ;delay value 1
  74. HANG2        equ    $8000        ;delay value 2
  75.  
  76. DIRCOUNT        equ    9        ;no of dir listing entries
  77.  
  78.  
  79. * main variable block declarations
  80.  
  81.  
  82.         rsreset
  83.  
  84. dos_base        rs.l    1    ;library bases
  85. int_base        rs.l    1
  86. graf_base    rs.l    1
  87. consoledev    rs.l    1
  88.  
  89. ms_handle    rs.l    1    ;screen handle
  90.  
  91. mw_handle    rs.l    1    ;main window handle
  92. mw_viewport    rs.l    1    ;plus rastport etc
  93. mw_rastport    rs.l    1
  94. mw_userport    rs.l    1
  95.  
  96. mw_IDCMP        rs.l    1    ;main window IDCMP
  97.  
  98. mw_bitmap    rs.l    1    ;main window Bitmap ptr
  99. mw_bwidth    rs.w    1    ;width in pixels
  100. mw_bheight    rs.w    1    ;height in pixels
  101. mw_bplanes    rs.w    1    ;no of bitplanes
  102.  
  103. event_class    rs.l    1    ;Intuition message
  104. menu_id        rs.w    1    ;data
  105. shift_stat    rs.w    1
  106. gadget_id    rs.l    1
  107. mouse_xpos    rs.w    1
  108. mouse_ypos    rs.w    1
  109.  
  110. gadget_list    rs.l    1    ;ptr to current gadget list
  111.  
  112. menu_strip    rs.l    1    ;ptr to current menu strip
  113. menu_list    rs.l    1    ;ptr to list for current menu
  114.  
  115. ReqCount        rs.w    1    ;no of active requesters
  116. ThisReq        rs.l    1    ;ptr to active rhb
  117.  
  118. mp_across    rs.w    1    ;square pointed to by the
  119. mp_down        rs.w    1    ;mouse pointer
  120. oldmpac        rs.w    1    ;and old square values
  121. oldmpdn        rs.w    1
  122.  
  123. topaz_font    rs.l    1    ;ptr to Font struct
  124.  
  125. currsq        rs.w    1    ;used for repeated square changing
  126.  
  127. grid_bmap    rs.l    1    ;ptr to grid BitMap structure
  128. grid_width    rs.w    1    ;width in pixels
  129. grid_height    rs.w    1    ;height in pixels
  130. grid_planes    rs.w    1    ;no of bitplanes
  131.  
  132. grid_rp        rs.l    1    ;ptr to synthetic RastPort
  133. grid_tmpras    rs.l    1    ;ptr to TmpRas for it
  134. grid_trbuf    rs.l    1    ;ptr to buffer to use
  135.  
  136. grid_array    rs.l    1    ;ptr to "char" array (actually UWORD)
  137. undo_array    rs.l    1    ;ptr to undo array (new for 1.2)
  138.  
  139. grid_across    rs.w    1    ;no of squares across
  140. grid_down    rs.w    1    ;no of squares down
  141. grid_bytes    rs.l    1    ;no of bytes in array
  142.  
  143. grid_offset    rs.l    1    ;offset to current square in array.
  144.  
  145. grid_firstx    rs.w    1    ;across sq addr, top left corner
  146. grid_firsty    rs.w    1    ;down sq addr, top left corner
  147.  
  148. grid_hl        rs.w    1    ;upper and lower coord limits for
  149. grid_hu        rs.w    1    ;crossword grid
  150. grid_vl        rs.w    1
  151. grid_vu        rs.w    1
  152.  
  153. grid_hscrl    rs.w    1    ;used to determine pot values
  154. grid_vscrl    rs.w    1    ;for main screen PropGadgets
  155.  
  156. clue_list    rs.l    1    ;ptr to clue list
  157. clue_texts    rs.l    1    ;ptr to clue texts
  158. clue_endptr    rs.l    1    ;ptr to end of current texts
  159. clue_thisone    rs.l    1    ;ptr to current clue text
  160. clue_editlen    rs.w    1    ;length of current clue text
  161.  
  162. clue_AcEntry    rs.l    1    ;ptr to clue list entries
  163. clue_DnEntry    rs.l    1    ;for marking solved clues
  164.  
  165. pick_hpos    rs.w    1    ;square position of
  166. pick_vpos    rs.w    1    ;picked clue
  167.  
  168. pick_offset    rs.l    1    ;offset for picked clue
  169.  
  170. pick_across    rs.w    1    ;across clue no. picked
  171. pick_Ach        rs.w    1    ;and its position
  172. pick_Acv        rs.w    1
  173.  
  174. pick_down    rs.w    1    ;down clue no.
  175. pick_Dnh        rs.w    1    ;and its position
  176. pick_Dnv        rs.w    1
  177.  
  178. solve_ptr    rs.l    1    ;ptr to clue text for solve req
  179.  
  180. soln_across    rs.l    1    ;ptrs to various solution
  181. soln_down    rs.l    1    ;texts
  182.  
  183. savechar        rs.w    1    ;in case char accidentally erased
  184. save_h        rs.w    1    ;position of saved char
  185. save_v        rs.w    1
  186.  
  187. WSCount        rs.w    1    ;no of white squares
  188.  
  189. SLCount        rs.w    1    ;no of solutions entered
  190.  
  191. irt_itext    rs.l    1    ;ptr to InfoReq ITexts
  192. irt_tlist    rs.l    1    ;ptr to my text lists
  193. irt_count    rs.w    1    ;no of texts to display
  194.  
  195. erasecode    rs.l    1    ;used by "Enter Solution" requester
  196. solvecode    rs.l    1    ;as is this
  197.  
  198. dp_window1    rs.l    1    ;used by Disc Panel code
  199. dp_rastport1    rs.l    1
  200. dp_window2    rs.l    1    ;for window reference
  201. dp_rastport2    rs.l    1
  202.  
  203. dp_userport    rs.l    1
  204.  
  205. dp_window3    rs.l    1    ;for DiscInfoReq (actually a
  206. di_userport    rs.l    1    ;window)
  207. di_rastport    rs.l    1
  208.  
  209. tmp_across    rs.w    1    ;values used by SetAcross() &
  210. tmp_down        rs.w    1    ;SetDown() etc.
  211.  
  212. tmp_size        rs.l    1    ;temporary saved new grid size
  213.  
  214. dir_name        rs.l    1    ;ptr to directory name for SortDir()
  215. dir_rename    rs.l    1    ;ptr to buffer for Rename gadget
  216.  
  217. dir_lock        rs.l    1    ;lock for given dir
  218. dir_iblk        rs.l    1    ;ptr to file info block
  219.  
  220. dir_flist    rs.l    1    ;ptr to files list
  221. dir_fcount    rs.w    1    ;no of entries in files list
  222. dir_dlist    rs.l    1    ;ptr to dirs list
  223. dir_dcount    rs.w    1    ;no of entries in dir list
  224. dir_nodes    rs.l    1    ;ptr to node space
  225. dir_strings    rs.l    1    ;ptr to string space
  226.  
  227. dir_nodepos    rs.l    1    ;ptr to currently processed node
  228. dir_strpos    rs.l    1    ;ptr to 1st new string area
  229.  
  230. dir_error    rs.w    1    ;error code returned by SortDir()
  231.  
  232. dir_entnum    rs.w    1    ;total entry count from SortDir()
  233. dir_entpos    rs.w    1    ;1st entry accessed for dir listing
  234.  
  235. file_buffer    rs.l    1    ;ptr to file buffer
  236. file_size    rs.l    1    ;size of file buffer
  237. file_acs        rs.l    1    ;no of bytes in ACCL chunk
  238. file_dns        rs.l    1    ;no of bytes in DNCL chunk
  239.  
  240. file_shand    rs.l    1    ;file handle for saving
  241. file_lhand    rs.l    1    ;file handle for loading
  242.  
  243. file_oldname    rs.l    1    ;old name for rename/makedir/delete
  244. file_newname    rs.l    1    ;new name for rename
  245.  
  246. file_cwhd    rs.l    1    ;ptr to CWHD chunk on load
  247. file_grid    rs.l    1    ;ptr to GRID chunk on load
  248. file_accl    rs.l    1
  249. file_dncl    rs.l    1
  250.  
  251. fmt_port        rs.l    1    ;port created for disc formatting
  252. fmt_ioreq    rs.l    1    ;IORequest created for disc formatting
  253. fmt_trbuf    rs.l    1
  254. fmt_offset    rs.l    1
  255. fmt_error    rs.w    1
  256.  
  257. disc_error    rs.w    1    ;disc access error code. 0=OK.
  258.  
  259. lib_unopened    rs.w    1    ;unopened library code etc.
  260. error_code    rs.w    1    ;DOS error code
  261.  
  262. file_flags    rs.w    1    ;File handling flags
  263.  
  264. applic_flags    rs.w    1    ;Application flags
  265.  
  266. drv0        rs.b    1    ;flag byte for DF0 if it exists
  267. drv1        rs.b    1    ;flag byte for DF1 if it exists
  268. drv2        rs.b    1    ;flag byte for RAM if it exists
  269. drv3        rs.b    1    ;flag byte for DH if it exists
  270.  
  271. editon        rs.b    1    ;whether editing or not
  272. wantdir        rs.b    1    ;want new dir after disc error Y/N
  273.  
  274. vars_sizeof    rs.w    0
  275.  
  276.  
  277. applic_flag1    equ    applic_flags        ;Q T 5 E P C RM LM
  278. applic_flag2    equ    applic_flags+1        ;R E DP 4 3 HI H I
  279.  
  280.  
  281. * Flags:
  282.  
  283. * Flag1:
  284.  
  285. * Q    : main application quit flag. 0 = quit.
  286.  
  287. * T    : crossword type flag. 0 = normal, 1 = Daily Express Small
  288. *      Crossword (thick bars replace black squares).
  289.  
  290. * E    : Existence flag for clue list. 1=clue list exists,
  291. *      0 otherwise.
  292.  
  293. * P    : Picking flag. P=1 if picking a clue to edit or solve,
  294. *      P=0 otherwise.
  295.  
  296. * C    : Change bit. C=1 if changing square values with mouse
  297. *      pointer, C=0 if not.
  298.  
  299. * RM    : Right mouse button flag. 1=button held down.
  300. *      Conditioned by MENUDOWN message from Intuition.
  301.  
  302. * LM    : Left mouse button flag. 1=button held down.
  303. *      Conditioned by SELECTDOWN message from Intuition.
  304.  
  305. * Flag2:
  306.  
  307. * R    : requester flag. 1 = requester active.
  308.  
  309. * E    : execute flag. 0=requester CANCEL pressed,
  310. *            1=requester SELECT/EXECUTE pressed.
  311.  
  312. * DP    : DiscPanel flag. 0=not in DiscPanel, 1=in DiscPanel.
  313.  
  314. * HI    : Hold Info flag. 1=keep InfoRequester on, 0=
  315. *      exit InfoRequester at next button up message.
  316.  
  317. * H    : Help flag. 0=help OFF, 1=help ON.
  318.  
  319. * I    : inforequester flag. 0=inactive, 1=active.
  320.  
  321.  
  322. file_flag1    equ    file_flags    L S R D F M 1 0
  323. file_flag2    equ    file_flags+1    F R 5 4 3 2 1 0
  324.  
  325.  
  326. * File handling flags
  327.  
  328. * flag1:
  329.  
  330. * L    Load flag. 1=load function selected.
  331. * S    Save flag. 1=save function selected.
  332. * D    Delete flag. 1=delete function selected.
  333. * R    Rename flag. 1=rename function selected.
  334. * F    Format flag. 1=format function selected.
  335. * M    MakeDir flag. 1=make dir function selected.
  336.  
  337. * flag2:
  338.  
  339. * F    File selected flag. 1=filename chosen (hence Load, Save,
  340. *    etc., have a valid filename to work with).
  341.  
  342. * R    Rename selected flag. 1=valid rename name exists in the
  343. *    rename string gadget.
  344.  
  345.  
  346. * IORequest structure
  347.  
  348.  
  349.         rsreset
  350. io_MsgNode    rs.b    mn_sizeof
  351. io_Device    rs.l    1
  352. io_Unit        rs.l    1
  353. io_Command    rs.w    1
  354. io_Flags        rs.b    1
  355. io_Error        rs.b    1
  356. io_sizeof    rs.w    0
  357.  
  358.  
  359. * IOEXTRequest structure
  360.  
  361.  
  362.         rsreset
  363. ioext_Std    rs.b    io_sizeof
  364. ioext_Actual    rs.l    1
  365. ioext_Length    rs.l    1
  366. ioext_Data    rs.l    1
  367. ioext_Offset    rs.l    1
  368. ioext_sizeof    rs.w    0
  369.  
  370.  
  371. * IOTD structure
  372.  
  373.  
  374.         rsreset
  375. iotd_Std        rs.b    ioext_sizeof
  376. iotd_Count    rs.l    1
  377. iotd_SecLabel    rs.l    1
  378. iotd_sizeof    rs.w    0
  379.  
  380.  
  381. * Event Handler Block definition
  382. * Pointers are :
  383. * 1) pointer to code for mouse handling in absence of MENUVERIFY
  384. * 2) pointer to code for event handling
  385. * 3) pointer to IDCMP list to use
  386.  
  387.  
  388.         rsreset
  389.  
  390. ehb_mousecode    rs.l    1
  391. ehb_othercode    rs.l    1
  392. ehb_IDCMPlist    rs.l    1
  393.  
  394. ehb_sizeof    rs.w    0
  395.  
  396.  
  397. * Requester handling block structure
  398.  
  399.  
  400.         rsreset
  401.  
  402. rhb_Requester    rs.l    1    ;ptr to requester to handle
  403. rhb_EHB        rs.l    1    ;ptr to event handler block
  404. rhb_Window    rs.l    1    ;ptr to Window Handle to use
  405. rhb_UserPort    rs.l    1    ;ptr to UserPort of above window
  406. rhb_IDCMP    rs.l    1    ;IDCMP for this window
  407. rhb_PreCode    rs.l    1    ;Code to run before event handling
  408.  
  409. rhb_sizeof    rs.w    0
  410.  
  411.  
  412. * Clue List Entry data structure
  413.  
  414.  
  415.         rsreset
  416.  
  417. cle_Num        rs.w    1    ;clue number
  418. cle_AcSq        rs.w    1    ;Across square value
  419. cle_DnSq        rs.w    1    ;Down square value
  420. cle_Text        rs.l    1    ;Text:NULL if none present
  421. cle_Solved    rs.b    1    ;0 if not solved:-1 otherwise
  422. cle_Filler    rs.b    1
  423.  
  424. cle_sizeof    rs.w    0
  425.  
  426.  
  427. * Clue List Header data structure
  428.  
  429.  
  430.         rsreset
  431.  
  432. clh_AcList    rs.l    1    ;ptr to Across List
  433. clh_AcCount    rs.w    1    ;no of entries in this list
  434. clh_DnList    rs.l    1    ;ptr to Down List
  435. clh_DnCount    rs.w    1    ;no of entries in this list
  436.  
  437. clh_sizeof    rs.w    0
  438.  
  439.  
  440. * actual application program code. First step is to allocate space
  441. * for my variable block, referenced off A6.
  442.  
  443.  
  444.         section    Program,CODE
  445.  
  446.  
  447. main        move.l    #vars_sizeof,d0
  448.         move.l    #MEMF_VARS,d1
  449.         CALLEXEC    AllocMem
  450.         tst.l    d0
  451.  
  452.         beq    cock_up_1
  453.  
  454.         move.l    d0,a6
  455.  
  456.  
  457. * NOTE : a6 to point to my variables ALWAYS! ALL routines MUST leave
  458. * a6 intact from this point onwards!
  459.  
  460.  
  461.         bsr    InitVars
  462.  
  463.         bsr    OpenAllLibs    ;open all libraries needed
  464.  
  465.         move.w    d1,lib_unopened(a6)
  466.  
  467.         tst.l    d0
  468.         beq    cock_up_2    ;can't do it
  469.  
  470.  
  471. * Now open the TOPAZ80 font (which is ROM-resident). Because I'm forcing
  472. * use of TOPAZ80 I don't need the Diskfont Library since TOPAZ80 is a
  473. * ROM-resident font.
  474.  
  475.  
  476.         lea    Topaz_80(pc),a0    ;I want Topaz-80
  477.  
  478.         lea    my_new_screen(pc),a1    ;this to be
  479.         move.l    a0,16(a1)        ;sure of it
  480.  
  481.         CALLGRAF    OpenFont
  482.         move.l    d0,topaz_font(a6)    ;got it?
  483.         beq    cock_up_2a    ;oops...
  484.  
  485.  
  486. * Here link Topaz font into all IntuiTexts that need it (such as the
  487. * InfoRequester/QueryRequester texts, & the gadgets where needed).
  488.  
  489.  
  490.         bsr    LinkFonts
  491.  
  492.  
  493. * Here create a custom BitMap. Don't forget to change size (here 320x256)
  494. * and planes (here 4) for other applications!
  495.  
  496.  
  497.         move.w    #320,d0
  498.         move.w    #256,d1
  499.         moveq    #4,d2
  500.         move.w    d0,mw_bwidth(a6)
  501.         move.w    d1,mw_bheight(a6)
  502.         move.w    d2,mw_bplanes(a6)
  503.         bsr    NewBitMap    ;create my custom BitMap
  504.         beq    cock_up_3    ;can't do it
  505.  
  506.         move.l    d0,mw_bitmap(a6)
  507.  
  508.         lea    my_new_screen(pc),a0
  509.         lea    my_new_window(pc),a1
  510.         move.l    d0,a2
  511.         bsr    OpenSW        ;open my screen & window
  512.         tst.l    d3
  513.         beq    cock_up_4    ;can't do it
  514.  
  515.         move.l    a0,ms_handle(a6)    ;screen handle
  516.  
  517.         move.l    a1,mw_handle(a6)        ;window handle
  518.         move.l    d0,mw_viewport(a6)    ;it's viewport
  519.         move.l    d1,mw_rastport(a6)    ;it's rastport
  520.         move.l    d2,mw_userport(a6)    ;it's userport
  521.  
  522.  
  523. * Now set ColorMap
  524.  
  525.  
  526.         move.l    mw_viewport(a6),a0
  527.         lea    Palette(pc),a1
  528. ;        moveq    #16,d0
  529.         moveq    #32,d0
  530.         CALLGRAF    LoadRGB4
  531.  
  532.  
  533. * Now set drawing mode for main RastPort.
  534.  
  535.  
  536.         move.l    mw_rastport(a6),a1
  537.         moveq    #RP_JAM2,d0
  538.         CALLGRAF    SetDrMd
  539.  
  540.  
  541. * Now set the Font for the main RastPort.
  542.  
  543.  
  544.         move.l    mw_rastport(a6),a1
  545.         move.l    topaz_font(a6),a0
  546.         CALLGRAF    SetFont
  547.  
  548.  
  549. * Now pop in the "Zz" pointer
  550.  
  551.  
  552.         bsr    HangPointer
  553.  
  554.  
  555. * Now create BitMap for CrossWord grid.
  556.  
  557.  
  558.         move.w    #GRID_BX,d0    ;grid size
  559.         move.w    #GRID_BY,d1
  560.         moveq    #2,d2        ;& bitplane count
  561.         move.w    d0,grid_width(a6)
  562.         move.w    d1,grid_height(a6)
  563.         move.w    d2,grid_planes(a6)
  564.         bsr    NewBitMap
  565.         move.l    d0,grid_bmap(a6)    ;got it?
  566.         beq    cock_up_5    ;exit if not
  567.  
  568.  
  569. * Now create crossword grid array. This is a WORD array, low byte of
  570. * each word = ASCII char in white square (SPACE if blank, ASCII NUL
  571. * if black square on normal grid), high byte = bar bits for type 2
  572. * crossword.
  573.  
  574.  
  575.         move.l    grid_bytes(a6),d0
  576.         move.l    #MEMF_VARS,d1
  577.         CALLEXEC    AllocMem
  578.         move.l    d0,grid_array(a6)        ;got array?
  579.         beq    cock_up_6
  580.  
  581.         move.l    grid_bytes(a6),d0
  582.         move.l    #MEMF_VARS,d1
  583.         CALLEXEC    AllocMem
  584.         move.l    d0,undo_array(a6)        ;got array?
  585.         beq    cock_up_7
  586.  
  587.  
  588. * Now create a synthetic RastPort for the crossword grid.
  589.  
  590.  
  591.         move.l    grid_bmap(a6),a0    ;ptr to bitmap to use
  592.         bsr    MakeOwnRastPort
  593.         move.l    d0,grid_rp(a6)
  594.         beq    cock_up_8
  595.  
  596.  
  597. * Now create a TmpRas for the synthetic RastPort (VITAL!).
  598.  
  599.  
  600.         move.l    #tr_sizeof,d0
  601.         move.l    #MEMF_VARS,d1
  602.         CALLEXEC    AllocMem
  603.         move.l    d0,grid_tmpras(a6)
  604.         beq    cock_up_9
  605.  
  606.         move.w    #320,d0
  607.         move.w    #256,d1
  608.         CALLGRAF    AllocRaster
  609.         move.l    d0,grid_trbuf(a6)    ;area for TmpRas to use
  610.         beq    cock_up_10    ;and exit if can't get it
  611.  
  612.         move.l    d0,a1
  613.         move.l    grid_tmpras(a6),a0
  614.         move.l    #320*256/8,d0
  615.         CALLGRAF    InitTmpRas    ;set up the TmpRas
  616.  
  617.         move.l    grid_tmpras(a6),a0    ;get TmpRas
  618.         move.l    grid_rp(a6),a1        ;and RastPort
  619.         move.l    a0,rp_TmpRas(a1)    ;and link TmpRas to RastPort
  620.  
  621.  
  622. * Now set the Font for the synthetic RastPort.
  623.  
  624.  
  625.         move.l    grid_rp(a6),a1
  626.         move.l    topaz_font(a6),a0
  627.         CALLGRAF    SetFont
  628.  
  629.  
  630. * Now set drawing mode for synthetic RastPort.
  631.  
  632.  
  633.         move.l    grid_rp(a6),a1
  634.         moveq    #RP_JAM1,d0
  635.         CALLGRAF    SetDrMd
  636.  
  637.  
  638. * Now fill the RastPort with colour 1.
  639.  
  640.  
  641.         move.l    grid_rp(a6),a1
  642.         moveq    #1,d0
  643.         CALLGRAF    SetRast
  644.  
  645.  
  646. * Now initialise the static BitMap structures for the squares
  647. * used by the blitter.
  648.  
  649.  
  650.         lea    bsbmap(pc),a0
  651.         moveq    #2,d0
  652.         moveq    #16,d1
  653.         moveq    #10,d2
  654.         CALLGRAF    InitBitMap
  655.  
  656.         lea    wsbmap(pc),a0
  657.         moveq    #2,d0
  658.         moveq    #16,d1
  659.         moveq    #10,d2
  660.         CALLGRAF    InitBitMap
  661.  
  662.         lea    vbsbmap(pc),a0
  663.         moveq    #2,d0
  664.         moveq    #16,d1
  665.         moveq    #10,d2
  666.         CALLGRAF    InitBitMap
  667.  
  668.         lea    hbsbmap(pc),a0
  669.         moveq    #2,d0
  670.         moveq    #16,d1
  671.         moveq    #10,d2
  672.         CALLGRAF    InitBitMap
  673.  
  674.         lea    bbsbmap(pc),a0
  675.         moveq    #2,d0
  676.         moveq    #16,d1
  677.         moveq    #10,d2
  678.         CALLGRAF    InitBitMap
  679.  
  680.  
  681. * Now link the individual BitMap areas into the BitMap structures
  682.  
  683.  
  684.         lea    bsquare,a0    ;ptr to 1st image data
  685.         move.l    a0,d0        ;copy it
  686.         lea    sqtable(pc),a1    ;ptr to bitmap ptrs
  687.  
  688.         move.l    (a1)+,a2        ;get ptr to BitMap
  689.         move.l    a0,bm_Planes(a2)    ;link in image data
  690.         addq.l    #4,a2
  691.         move.l    d0,bm_Planes(a2)
  692.         add.w    #20,a0        ;point to next image
  693.  
  694.         move.l    (a1)+,a2        ;get ptr to BitMap
  695.         move.l    a0,bm_Planes(a2)    ;link in image data
  696.         addq.l    #4,a2
  697.         move.l    d0,bm_Planes(a2)
  698.         add.w    #20,a0        ;point to next image
  699.  
  700.         move.l    (a1)+,a2        ;get ptr to BitMap
  701.         move.l    a0,bm_Planes(a2)    ;link in image data
  702.         addq.l    #4,a2
  703.         move.l    d0,bm_Planes(a2)
  704.         add.w    #20,a0        ;point to next image
  705.  
  706.         move.l    (a1)+,a2        ;get ptr to BitMap
  707.         move.l    a0,bm_Planes(a2)    ;link in image data
  708.         addq.l    #4,a2
  709.         move.l    d0,bm_Planes(a2)
  710.         add.w    #20,a0        ;point to next image
  711.  
  712.         move.l    (a1)+,a2        ;get ptr to BitMap
  713.         move.l    a0,bm_Planes(a2)    ;link in image data
  714.         addq.l    #4,a2
  715.         move.l    d0,bm_Planes(a2)
  716.         add.w    #20,a0        ;point to next image
  717.  
  718.  
  719. * Initialise the grid with all black squares & display it
  720.  
  721.  
  722.         bsr    FillBlack2
  723.  
  724.  
  725. * Initialise the Undo Array (1.2)...
  726.  
  727.  
  728.         bsr    InitUndo
  729.  
  730.  
  731. * Here link in menu to main window if wanted. DO NOT FORGET TO
  732. * SET menu_list(a6) AND menu_strip(a6) VARIABLES BEFORE LINKING
  733. * IN THE MENU, OR ELSE DO_MENUS() WON'T WORK!
  734.  
  735.  
  736.         move.l    mw_handle(a6),a0
  737.         lea    my_main_menu(pc),a1
  738.         move.l    a1,menu_strip(a6)
  739.         lea    menulist_1(pc),a2
  740.         move.l    a2,menu_list(a6)
  741.         CALLINT    SetMenuStrip
  742.  
  743.  
  744. * Now pop in the MENUVERIFY! Actually doesn't because it's not
  745. * needed anymore, but I'll leave it in because it doesn't do
  746. * any harm...
  747.  
  748.  
  749.         move.l    mw_IDCMP(a6),d0
  750.         move.l    mw_handle(a6),a0
  751.         CALLINT    ModifyIDCMP
  752.  
  753.  
  754. * Here set up the screen PropGadgets ready...
  755.  
  756.  
  757.         bsr    SetMainHVPots
  758.  
  759.  
  760. * Now pop up my copyright message...
  761.  
  762.  
  763.         lea    IRT_1(pc),a0
  764.         lea    CopyRight(pc),a1
  765.         moveq    #8,d0
  766.         move.l    a0,irt_itext(a6)
  767.         move.l    a1,irt_tlist(a6)
  768.         move.w    d0,irt_count(a6)
  769.  
  770.         bsr    LinkInfoText
  771.  
  772.         bsr    ShowInfoReq
  773.  
  774.  
  775. * Ok, this is where we do a SetPointer() call and see if we've got our
  776. * flash pencil pointer...
  777.  
  778.  
  779.         bsr    MainPointer
  780.  
  781.  
  782. * Now we find out which drives are linked into the system. Because the
  783. * disc access panel isn't up, I can set the gadget flags directly & not
  784. * have to unlink/refresh etc. So the WhichDrives() routine does just
  785. * that.
  786.  
  787.  
  788.         bsr    WhichDrives
  789.  
  790.  
  791. * If DF0: is missing for some reason, pop up an InfoReq telling user
  792. * to get his Amiga mended.
  793.  
  794.  
  795.         nop
  796.  
  797.  
  798. * Here handle Intuition Events
  799.  
  800.  
  801. main_1        move.l    mw_userport(a6),a0
  802.         lea    ehb_std(pc),a5
  803.  
  804.         bsr    DoEvent        ;completely event driven!
  805.  
  806.         tst.b    applic_flag1(a6)    ;quit the program?
  807.         bmi.s    main_1        ;no (quicker than btst etc)
  808.  
  809.  
  810. * Once application no longer active, deallocate everything
  811. * in a hygenic fashion & return to CLI/WorkBench. Don't forget
  812. * to ClearMenuStrip() if SetMenuStrip() used above! Also, kill
  813. * off our custom pointer...
  814.  
  815.  
  816. main_2        bsr    FreeText        ;get rid of clue texts
  817.  
  818.         bsr    DisposeClueList    ;and clue list entries
  819.  
  820.         move.l    mw_handle(a6),a0
  821.         CALLINT    ClearPointer
  822.  
  823.         move.l    mw_handle(a6),a0
  824.         CALLINT    ClearMenuStrip
  825.  
  826. cock_up_10    move.l    grid_trbuf(a6),d0        ;free the TmpRas buffer
  827.         beq.s    cock_up_9
  828.         move.l    d0,a0
  829.         move.w    #320,d0
  830.         move.w    #256,d1
  831.         CALLGRAF    FreeRaster
  832.  
  833. cock_up_9    move.l    grid_tmpras(a6),d0    ;free the TmpRas
  834.         beq.s    cock_up_8
  835.         move.l    d0,a1
  836.         move.l    #tr_sizeof,d0
  837.         CALLEXEC    FreeMem
  838.  
  839. cock_up_8    move.l    grid_rp(a6),a0        ;free the synthetic
  840.         bsr    KillOwnRastPort        ;RastPort
  841.  
  842. cock_up_7    move.l    undo_array(a6),d0        ;destroy undo
  843.         beq.s    cock_up_7        ;array
  844.         move.l    d0,a1
  845.         move.l    grid_bytes(a6),d0
  846.         CALLEXEC    FreeMem
  847.  
  848. cock_up_6    move.l    grid_array(a6),d0        ;destroy grid
  849.         beq.s    cock_up_5        ;word array
  850.         move.l    d0,a1
  851.         move.l    grid_bytes(a6),d0
  852.         CALLEXEC    FreeMem
  853.  
  854. cock_up_5    move.l    grid_bmap(a6),a0        ;free up grid BitMap
  855.         move.w    grid_width(a6),d0
  856.         move.w    grid_height(a6),d1
  857.         move.w    grid_planes(a6),d2
  858.         bsr    DisposeBitMap
  859.  
  860.         move.l    ms_handle(a6),a0
  861.         move.l    mw_handle(a6),a1
  862.  
  863. cock_up_4    bsr    CloseSW        ;close screen, window
  864.  
  865. cock_up_3    move.w    mw_bwidth(a6),d0
  866.         move.w    mw_bheight(a6),d1
  867.         move.w    mw_bplanes(a6),d2
  868.         move.l    mw_bitmap(a6),a0
  869.         bsr    DisposeBitMap    ;get rid of main BitMap
  870.  
  871. cock_up_2a    move.l    topaz_font(a6),d0    ;closing font?
  872.         beq.s    cock_up_2    ;nope
  873.         move.l    d0,a1
  874.         CALLGRAF    CloseFont    ;else stop using it
  875.  
  876. cock_up_2    bsr    CloseAllLibs    ;close all libraries
  877.  
  878.  
  879. * Don't forget to free the
  880. * variable block!
  881.  
  882.  
  883.         move.l    a6,a1
  884.         move.l    #vars_sizeof,d0
  885.         CALLEXEC    FreeMem
  886.  
  887. cock_up_1    moveq    #0,d0
  888.         rts
  889.  
  890.  
  891. * InitVars(a6)
  892. * a6 = ptr to main program variables
  893. * initialise any special variables
  894.  
  895. * MODIFIABLE
  896.  
  897.  
  898. InitVars        moveq    #15,d0            ;set up initial
  899.         move.w    d0,grid_across(a6)    ;grid size.
  900.         move.w    d0,grid_down(a6)
  901.         move.w    d0,d1
  902.         mulu    d0,d1            ;no of WORDS in array
  903.         add.l    d1,d1
  904.         move.l    d1,grid_bytes(a6)        ;size of grid in BYTES
  905.  
  906.         moveq    #-1,d0            ;just in case the
  907.         move.w    d0,mp_across(a6)        ;mouse pointer starts
  908.         move.w    d0,mp_down(a6)        ;off the grid
  909.         move.w    d0,oldmpac(a6)
  910.         move.w    d0,oldmpdn(a6)
  911.  
  912.         moveq    #1,d0
  913.         move.w    d0,grid_firstx(a6)    ;TLC square #
  914.         move.w    d0,grid_firsty(a6)    ;across & down
  915.  
  916.         move.l    #idcmp1+idcmp2,d0
  917.         add.l    #idcmp3+idcmp4,d0        ;set up the
  918. ;        add.l    #MENUVERIFY,d0        ;default IDCMP
  919.         move.l    d0,mw_IDCMP(a6)        ;for main window
  920.  
  921.         lea    ReqBlock(pc),a0        ;set up the
  922.         lea    ehb_req(pc),a1        ;requester event
  923.         moveq    #0,d0            ;handling block
  924.         move.l    d0,rhb_Requester(a0)    ;(static structure)
  925.         move.l    a1,rhb_EHB(a0)
  926.         move.l    d0,rhb_Window(a0)
  927.         move.l    d0,rhb_UserPort(a0)
  928.         move.l    d0,rhb_IDCMP(a0)
  929.         move.l    d0,rhb_PreCode(a0)
  930.         move.l    a0,ThisReq(a6)        ;& save ptr to it
  931.  
  932.         lea    IRT_1(pc),a0        ;ptr to InfoReq
  933.         move.l    a0,irt_itext(a6)        ;IntuiTexts
  934.         move.l    d0,irt_tlist(a6)        ;no TList
  935.         move.w    d0,irt_count(a6)        ;entry count = 0
  936.  
  937.         move.w    #GRID_LEFT,d0
  938.         move.w    d0,grid_hl(a6)
  939.         move.w    #SQ_X,d1
  940.         mulu    grid_across(a6),d1
  941.         add.w    d1,d0
  942.         subq.w    #1,d0
  943.         move.w    d0,grid_hu(a6)
  944.  
  945.         move.w    #GRID_UP,d0
  946.         move.w    d0,grid_vl(a6)
  947.         move.w    #SQ_Y,d1
  948.         mulu    grid_down(a6),d1
  949.         add.w    d1,d0
  950.         subq.w    #1,d0
  951.         move.w    d0,grid_vu(a6)
  952.  
  953.         moveq    #0,d0
  954.  
  955.         move.w    d0,ReqCount(a6)
  956.         move.w    d0,applic_flags(a6)
  957.  
  958.         lea    CLHeader(pc),a0        ;set up the
  959.         move.l    a0,clue_list(a6)        ;clue list header
  960.  
  961.         move.l    d0,clh_AcList(a0)        ;and ensure that
  962.         move.w    d0,clh_AcCount(a0)    ;no list data
  963.         move.l    d0,clh_DnList(a0)        ;exists
  964.         move.w    d0,clh_DnCount(a0)
  965.  
  966.         move.l    d0,clue_texts(a6)        ;and no texts either
  967.  
  968.         lea    AcrossBuf(pc),a0
  969.         move.l    a0,soln_across(a6)
  970.         lea    DownBuf(pc),a0
  971.         move.l    a0,soln_down(a6)
  972.  
  973.         bset    #7,applic_flag1(a6)    ;not quitting program!
  974.  
  975.         moveq    #" ",d0
  976.         move.w    d0,savechar(a6)
  977.         move.w    d0,currsq(a6)
  978.  
  979.         rts
  980.  
  981.  
  982. * OpenAllLibs(a6) -> d0/d1
  983. * a6 = ptr to my main variable block
  984. * returns success/failure in d0 (success=TRUE)
  985. * if failed to open any library, returns
  986. * library code number in d1
  987.  
  988. * a1 corrupt.
  989.  
  990. * NON-MODIFIABLE.
  991.  
  992. OpenAllLibs    lea    dos_name(pc),a1    ;DOS library
  993.         moveq    #0,d0
  994.         CALLEXEC    OpenLibrary    ;get her address
  995.         moveq    #1,d1        ;code if not available
  996.         move.l    d0,dos_base(a6)    ;is it?
  997.         beq.s    OAL_done        ;bye-bye if not
  998.  
  999.         lea    int_name(pc),a1    ;Intuition library
  1000.         moveq    #0,d0
  1001.         CALLEXEC    OpenLibrary    ;get her address
  1002.         moveq    #2,d1        ;code if not available
  1003.         move.l    d0,int_base(a6)    ;is it?
  1004.         beq.s    OAL_done        ;bye-bye if not
  1005.  
  1006.         lea    graf_name(pc),a1    ;Graphics library
  1007.         moveq    #0,d0
  1008.         CALLEXEC    OpenLibrary    ;get her address
  1009.         moveq    #3,d1        ;code if not available
  1010.         move.l    d0,graf_base(a6)    ;is it?
  1011.         beq.s    OAL_done        ;bye-bye if not
  1012.  
  1013.         moveq    #TRUE,d0        ;all's well!
  1014.         moveq    #0,d1
  1015.  
  1016. OAL_done        rts
  1017.  
  1018.  
  1019. * CloseAllLibs(a6)
  1020. * Close all libraries opened by OpenAllLibs()
  1021. * Only closes those that were opened!
  1022.  
  1023. * d0/a1 corrupt
  1024.  
  1025. * NON-MODIFIABLE.
  1026.  
  1027.  
  1028. CloseAllLibs    move.l    graf_base(a6),d0    ;exists?
  1029.         beq.s    CAL_2        ;no!
  1030.         move.l    d0,a1
  1031.         CALLEXEC    CloseLibrary    ;else close it
  1032.  
  1033. CAL_2        move.l    int_base(a6),d0    ;exists?
  1034.         beq.s    CAL_1        ;no!
  1035.         move.l    d0,a1
  1036.         CALLEXEC    CloseLibrary    ;else close it
  1037.  
  1038. CAL_1        move.l    dos_base(a6),d0    ;exists?
  1039.         beq.s    CAL_done        ;no!
  1040.         move.l    d0,a1
  1041.         CALLEXEC    CloseLibrary    ;else close it
  1042.  
  1043. CAL_done        rts
  1044.  
  1045.  
  1046. * Workspace allocation defs for NewBitMap() etc
  1047.  
  1048.  
  1049. nbm_width    equ    -2
  1050. nbm_height    equ    -4
  1051. nbm_depth    equ    -6
  1052. nbm_pointer    equ    -10
  1053. nbm_ssize    equ    -14
  1054. nbm_space    equ    -18
  1055.  
  1056.  
  1057. * NewBitMap(d0,d1,d2) -> d0
  1058. * Allocate memory for, & initialise a BitMap
  1059. * structure. Also allocate all of the Raster
  1060. * bitplanes needed for it, & link them in.
  1061. * d0 = width in pixels
  1062. * d1 = height in pixels
  1063. * d2 = depth in pixels
  1064.  
  1065. * returns d0 = ptr to bitmap structure if allocated AND
  1066. * all Raster bitplanes obtained, else NULL
  1067.  
  1068. * d0-d2/d7/a0/a4 corrupt
  1069.  
  1070. * NON-MODIFIABLE.
  1071.  
  1072.  
  1073. NewBitMap    link    a5,#nbm_space    ;reserve some workspace!
  1074.  
  1075.         move.w    d0,nbm_width(a5)
  1076.         move.w    d1,nbm_height(a5)
  1077.         move.w    d2,nbm_depth(a5)
  1078.  
  1079.         moveq    #bm_Planes,d0
  1080.         lsl.w    #2,d2
  1081.         add.w    d2,d0        ;size of BitMap structure
  1082.         ext.l    d0
  1083.         move.l    d0,nbm_ssize(a5)    ;keep it!
  1084.  
  1085.         move.l    #MEMF_PUBLIC,d1
  1086.         CALLEXEC    AllocMem
  1087.         move.l    d0,nbm_pointer(a5)    ;save pointer
  1088.         beq    NBM_done            ;oops...
  1089.  
  1090.         move.l    d0,a0
  1091.         move.w    nbm_depth(a5),d0
  1092.         move.w    nbm_width(a5),d1
  1093.         move.w    nbm_height(a5),d2
  1094.         CALLGRAF    InitBitMap        ;init BitMap struct
  1095.  
  1096.         move.w    nbm_depth(a5),d7        ;no of bitplanes
  1097.  
  1098.         move.l    nbm_pointer(a5),a4
  1099.         lea    bm_Planes(a4),a4        ;where Plane ptrs go
  1100.  
  1101. NBM_l1        move.w    nbm_width(a5),d0
  1102.         move.w    nbm_height(a5),d1
  1103.         CALLGRAF    AllocRaster        ;get a Raster bitplane
  1104.         move.l    d0,(a4)+            ;save pointer
  1105.         beq.s    NBM_b1            ;cock up!
  1106.  
  1107.         subq.w    #1,d7            ;done all bitplanes?
  1108.         bne.s    NBM_l1            ;back if not
  1109.  
  1110.         move.l    nbm_pointer(a5),d0    ;all's well-return ptr
  1111.         bra.s    NBM_done
  1112.  
  1113. * From here on, couldn't allocate a Raster bitplane. So deallocate
  1114. * those that exist, then deallocate the BitMap structure & return
  1115. * a zero pointer.
  1116.  
  1117. NBM_b1        move.l    nbm_pointer(a5),a0
  1118.         lea    bm_Planes(a0),a0
  1119.         move.l    a0,d7
  1120.  
  1121. NBM_l2        move.l    -(a4),a0        ;this one WAS allocated
  1122.         move.w    nbm_width(a5),d0    ;size across
  1123.         move.w    nbm_height(a5),d1    ;and down
  1124.         CALLEXEC    FreeRaster    ;get rid of it!
  1125.  
  1126.         cmp.l    a4,d7        ;last one?
  1127.         bcc.s    NBM_l2        ;no, go back
  1128.  
  1129.         move.l    nbm_ssize(a5),d0
  1130.         move.l    nbm_pointer(a5),a1    ;now free up the
  1131.         CALLEXEC    FreeMem            ;BitMap struct!
  1132.  
  1133.         moveq    #0,d0            ;return NULL ptr
  1134.  
  1135. NBM_done        unlk    a5
  1136.         rts
  1137.  
  1138.  
  1139. * DisposeBitMap(a0,d0,d1,d2)
  1140. * Get rid of allocated BitMap structure and its
  1141. * associated Raster bitplanes.
  1142. * a0 = ptr to BitMap to dispose of
  1143. * d0 = width of planes to dispose of
  1144. * d1 = height of planes to dispose of
  1145. * d2 = no of planes to dispose of
  1146.  
  1147. * d0/a0/a4 corrupt
  1148.  
  1149. * NON-MODIFIABLE.
  1150.  
  1151.  
  1152. DisposeBitMap    link    a5,#nbm_space
  1153.  
  1154.         move.w    d0,nbm_width(a5)
  1155.         move.w    d1,nbm_height(a5)
  1156.         move.w    d2,nbm_depth(a5)
  1157.  
  1158.         move.l    a0,d0        ;check if it exists
  1159.         beq.s    DBM_done        ;no it doesn't!
  1160.  
  1161.         move.l    a0,nbm_pointer(a5)    ;save BitMap ptr
  1162.         lea    bm_Planes(a0),a4        ;ptr to Plane ptrs!
  1163.  
  1164.         move.w    d2,d7            ;counter
  1165.         lsl.w    #2,d2
  1166.         add.w    #bm_Planes,d2
  1167.         ext.l    d2
  1168.         move.l    d2,nbm_ssize(a5)        ;size of struct also
  1169.  
  1170. DBM_l1        move.l    (a4)+,d0            ;get plane pointer
  1171.         beq.s    DBM_b1            ;doesn't exist
  1172.         move.l    d0,a0
  1173.         move.w    nbm_width(a5),d0
  1174.         move.w    nbm_height(a5),d1
  1175.         CALLGRAF    FreeRaster        ;get rid of raster
  1176.  
  1177. DBM_b1        subq.w    #1,d7            ;done?
  1178.         bne.s    DBM_l1            ;back if not
  1179.  
  1180.         move.l    nbm_pointer(a5),a1
  1181.         move.l    nbm_ssize(a5),d0
  1182.         CALLEXEC    FreeMem            ;get rid of BitMap
  1183.  
  1184. DBM_done        unlk    a5
  1185.         rts
  1186.  
  1187.  
  1188. * InitWindow(a0) -> d0-d2
  1189. * a0 = pointer to Window structure
  1190. * return parameters are:
  1191. * d0 = ViewPort pointer
  1192. * d1 = RastPort pointer
  1193. * d2 = User Port pointer
  1194.  
  1195. * NON-MODIFIABLE.
  1196.  
  1197.  
  1198. InitWindow    move.l    a0,-(sp)
  1199.         CALLINT    ViewPortAddress
  1200.         move.l    (sp)+,a0
  1201.         move.l    RastPort(a0),d1
  1202.         move.l    UserPort(a0),d2
  1203.         rts
  1204.  
  1205.  
  1206. * Workspace defs for OpenSW() etc
  1207.  
  1208.  
  1209. sw_screen    equ    -4
  1210. sw_window    equ    -8
  1211. sw_bitmap    equ    -12
  1212. sw_space        equ    -16
  1213.  
  1214.  
  1215. * OpenSW(a0,a1,a2) -> d0-d3,a0,a1
  1216. * Open Intuition screen and principal window
  1217. * a0 = pointer to NewScreen structure
  1218. * a1 = pointer to NewWindow structure
  1219. * a2 = pointer to custom BitMap structure if present
  1220. * NULL if not
  1221.  
  1222. * returns:
  1223. * a0 = pointer to Screen handle
  1224. * a1 = pointer to Window handle
  1225. * d0 = pointer to Window ViewPort
  1226. * d1 = pointer to Window RastPort
  1227. * d2 = pointer to Window User Port
  1228. * d3 = success/failure
  1229.  
  1230. * NON-MODIFIABLE.
  1231.  
  1232.  
  1233. OpenSW        link    a5,#sw_space
  1234.  
  1235.         move.l    a0,sw_screen(a5)        ;save input
  1236.         move.l    a1,sw_window(a5)        ;parameters
  1237.         move.l    a2,sw_bitmap(a5)
  1238.  
  1239.         move.l    a2,d0            ;got a bitmap?
  1240.         beq.s    OSW_2            ;no
  1241.  
  1242.         move.l    d0,28(a0)        ;set up bitmap ptr!
  1243.  
  1244. OSW_2        CALLINT    OpenScreen
  1245.         move.l    d0,sw_screen(a5)        ;save Screen handle
  1246.         beq.s    OSW_1            ;ain't got one!
  1247.  
  1248.         move.l    sw_bitmap(a5),d0        ;get bitmap ptr
  1249.  
  1250. OSW_3        move.l    sw_screen(a5),d1        ;get custom screen ptr
  1251.         move.l    sw_window(a5),a0
  1252. ;        move.l    d0,34(a0)        ;set up BitMap
  1253.         move.l    d1,30(a0)        ;and screen ptr
  1254.         CALLINT    OpenWindow
  1255.         move.l    d0,sw_window(a5)        ;save Window handle
  1256.         beq.s    OSW_1            ;oops...
  1257.  
  1258.         move.l    d0,a0
  1259.         bsr.s    InitWindow        ;get important
  1260.         moveq    #TRUE,d3            ;parameters
  1261.         bra.s    OSW_done            ;& signal success
  1262.  
  1263. OSW_1        moveq    #FALSE,d3        ;signal failure
  1264.         move.l    d3,d0        ;and clear all of
  1265.         move.l    d3,d1        ;the RastPort pointers
  1266.         move.l    d3,d2        ;etc.
  1267.  
  1268. OSW_done        move.l    sw_screen(a5),a0
  1269.         move.l    sw_window(a5),a1
  1270.  
  1271.         unlk    a5
  1272.         rts
  1273.  
  1274.  
  1275. * CloseSW(a0,a1)
  1276. * a0 = pointer to Screen
  1277. * a1 = pointer to Window
  1278. * closes screen/window opened by OpenSW()
  1279.  
  1280. * NON-MODIFIABLE.
  1281.  
  1282.  
  1283. CloseSW        move.l    a0,-(sp)        ;save screen ptr
  1284.         move.l    a1,d0        ;Window exists?
  1285.         beq.s    CSW_1        ;no
  1286.  
  1287.         move.l    d0,a0
  1288.         CALLINT    CloseWindow    ;else close it
  1289.  
  1290. CSW_1        move.l    (sp)+,a0
  1291.         CALLINT    CloseScreen    ;and close the screen
  1292.         rts
  1293.  
  1294.  
  1295. * MakeOwnRastPort(a0) -> d0
  1296. * a0 = ptr to BitMap to attach to it
  1297. * if wanted, NULL if none available.
  1298.  
  1299. * Create a RastPort if possible.
  1300. * returns D0=NULL if failed,
  1301. * D0=ptr to RastPort if succeeded
  1302.  
  1303. * d0/d1/a1/a5 corrupt
  1304.  
  1305.  
  1306. MakeOwnRastPort    movem.l    a0/a5,-(sp)
  1307.  
  1308.         move.l    #rp_sizeof,d0        ;create a
  1309.         move.l    #MEMF_VARS,d1        ;RastPort struct
  1310.         CALLEXEC    AllocMem
  1311.         move.l    d0,a5
  1312.         tst.l    d0            ;get one?
  1313.         beq.s    MORP_done        ;no, bye
  1314.  
  1315.         move.l    d0,a1            ;make it a real
  1316.         CALLGRAF    InitRastPort        ;RastPort
  1317.  
  1318.         move.l    (sp),d0            ;got a BitMap?
  1319.         beq.s    MORP_ok            ;no, don't link in
  1320.  
  1321.         move.l    d0,rp_BitMap(a5)    ;else link in BitMap
  1322.  
  1323. MORP_ok        move.l    a5,d0        ;pointer to RastPort
  1324.  
  1325. MORP_done    movem.l    (sp)+,a0/a5
  1326.         rts
  1327.  
  1328.  
  1329.  
  1330.  
  1331. * KillOwnRastPort(a0)
  1332. * a0 = ptr to RastPort to get rid of
  1333. * won't do it if RaspPort doesn't exist.
  1334.  
  1335. * d0/d1/a1/a5 corrupt
  1336.  
  1337.  
  1338. KillOwnRastPort    move.l    a0,d0        ;check if RastPort exists
  1339.         beq.s    KORP_done    ;it doesn't so exit
  1340.  
  1341.         move.l    d0,a1
  1342.         move.l    #rp_sizeof,d0
  1343.         CALLEXEC    FreeMem        ;get rid of it.
  1344.  
  1345. KORP_done    rts
  1346.  
  1347.  
  1348. * DisplayGrid(a6)
  1349. * a6 = ptr to main program variables
  1350.  
  1351. * Display the crossword grid on the backdrop window.
  1352.  
  1353. * d0-d6/a0-a1 corrupt
  1354.  
  1355.  
  1356. DisplayGrid    move.l    grid_bmap(a6),a0
  1357.  
  1358.         move.w    grid_firstx(a6),d0
  1359.         move.w    grid_firsty(a6),d1
  1360.  
  1361.         subq.w    #1,d0        ;convert to pixel
  1362.         mulu    #SQ_X,d0        ;coordinates
  1363. ;        addq.w    #2,d0
  1364.  
  1365.         subq.w    #1,d1
  1366.         mulu    #SQ_X,d1
  1367. ;        addq.w    #2,d1
  1368.  
  1369.         move.l    mw_rastport(a6),a1    ;window rastport!
  1370.  
  1371.         move.w    grid_hl(a6),d2
  1372.         move.w    grid_vl(a6),d3
  1373.  
  1374.         move.w    grid_across(a6),d4
  1375.         move.w    #MAX_DISPX,d6
  1376.         cmp.w    d6,d4
  1377.         bls.s    DGR_1
  1378.         move.w    d6,d4
  1379.  
  1380. DGR_1        move.w    grid_down(a6),d5
  1381.         move.w    #MAX_DISPY,d6
  1382.         cmp.w    d6,d5
  1383.         bls.s    DGR_2
  1384.         move.w    d6,d5
  1385.  
  1386. DGR_2        mulu    #SQ_X,d4
  1387.         addq.w    #4,d4
  1388.  
  1389.         mulu    #SQ_Y,d5
  1390.         addq.w    #4,d5
  1391.         move.w    #$CC,d6
  1392.  
  1393.         CALLGRAF    BltBitMapRastPort
  1394.  
  1395.         rts
  1396.  
  1397.  
  1398. * FillBlack2(a6)
  1399. * a6 = ptr to main program variables.
  1400.  
  1401. * Faster fillblack routine!
  1402.  
  1403. * d0-d3/a0-a1 corrupt
  1404.  
  1405.  
  1406. FillBlack2    btst    #6,applic_flag1(a6)    ;what crossword type?
  1407.         bne    FB2_Done            ;not valid for Type 2!
  1408.  
  1409.         btst    #1,applic_flag2(a6)    ;HELP on?
  1410.         beq.s    FB2_ok            ;skip if not
  1411.  
  1412.         lea    Help_BF,a0
  1413.         moveq    #5,d0
  1414.         bsr    _PopUpQR
  1415.  
  1416.         beq    FB2_Done
  1417.  
  1418. FB2_ok        move.l    grid_array(a6),a0        ;ptr to grid array
  1419.  
  1420.         moveq    #0,d2            ;value to use
  1421.  
  1422.         move.w    grid_across(a6),d0    ;no of across elements
  1423.         bra.s    FB2_A1
  1424. FB2_L1        move.w    grid_down(a6),d1        ;no of down elements
  1425.         bra.s    FB2_A2
  1426. FB2_L2        move.w    d2,(a0)+        ;clear array element
  1427. FB2_A2        dbra    d1,FB2_L2    ;back for more
  1428. FB2_A1        dbra    d0,FB2_L1    ;back for more
  1429.  
  1430.  
  1431. * Now clear the graphic area. Use the appropriate RectFill() calls to
  1432. * do this.
  1433.  
  1434.  
  1435.         move.l    grid_rp(a6),a1    ;set pen to
  1436.         moveq    #1,d0        ;white
  1437.         CALLGRAF    SetAPen
  1438.  
  1439.         move.w    grid_across(a6),d2    ;now fill area
  1440.         move.w    grid_down(a6),d3        ;with white
  1441.         mulu    #SQ_X,d2
  1442.         mulu    #SQ_Y,d3
  1443.         addq.l    #3,d2
  1444.         addq.l    #3,d3
  1445.         moveq    #0,d0
  1446.         moveq    #0,d1
  1447.         move.l    grid_rp(a6),a1
  1448.  
  1449.         movem.l    d0-d3/a1,-(sp)    ;save parameters
  1450.  
  1451.         CALLGRAF    RectFill
  1452.  
  1453.         move.l    grid_rp(a6),a1    ;set pen to
  1454.         moveq    #0,d0        ;black
  1455.         CALLGRAF    SetAPen
  1456.  
  1457.         movem.l    (sp)+,d0-d3/a1    ;recover parameters
  1458.  
  1459.         addq.l    #2,d0
  1460.         addq.l    #2,d1
  1461.         subq.l    #2,d2
  1462.         subq.l    #2,d3
  1463.  
  1464.         CALLGRAF    RectFill        ;now fill squares area
  1465.  
  1466.         bsr    DisplayGrid
  1467.  
  1468.         bsr    FreeText
  1469.  
  1470.         bsr    DisposeClueList
  1471.  
  1472.         bsr    InitUndo
  1473.  
  1474.         clr.w    WSCount(a6)    ;no more white squares
  1475.         clr.w    SLCount(a6)    ;no more solutions entered
  1476.  
  1477. FB2_Done        rts
  1478.  
  1479.  
  1480. * FillWhite2(a6)
  1481. * a6 = ptr to main program variables
  1482. * Faster white fill routine for filling crossword
  1483. * grid.
  1484.  
  1485. * Assumes type 1 grid (normal crossword), but also used for
  1486. * initialising a type 2 grid because of its action. Also
  1487. * kills clue lists off because they'll no longer be valid.
  1488.  
  1489. * d0-d3/a0-a1 corrupt
  1490.  
  1491.  
  1492. FillWhite2    btst    #1,applic_flag2(a6)    ;HELP on?
  1493.         beq.s    FW2_ok            ;skip if not
  1494.  
  1495.         lea    Help_WF,a0
  1496.         moveq    #5,d0
  1497.         bsr    _PopUpQR
  1498.  
  1499.         beq    FW2_Done
  1500.  
  1501. FW2_ok        move.l    grid_array(a6),a0        ;ptr to chars grid
  1502.         moveq    #0,d2
  1503.         move.b    #" ",d2
  1504.         move.w    grid_across(a6),d0    ;no of across squares
  1505.         bra.s    FW2_A1
  1506. FW2_L1        move.w    grid_down(a6),d1        ;no of down squares
  1507.         bra.s    FW2_A2
  1508. FW2_L2        move.w    d2,(a0)+        ;set grid element
  1509. FW2_A2        dbra    d1,FW2_L2    ;back for more
  1510. FW2_A1        dbra    d0,FW2_L1    ;back for more
  1511.  
  1512.  
  1513. * Now fill the graphic area with white squares.
  1514.  
  1515.  
  1516.         move.l    grid_rp(a6),a1    ;set pen to
  1517.         moveq    #1,d0        ;white
  1518.         CALLGRAF    SetAPen
  1519.  
  1520.         move.w    grid_across(a6),d2    ;now fill area
  1521.         move.w    grid_down(a6),d3        ;with white
  1522.         mulu    #SQ_X,d2
  1523.         mulu    #SQ_Y,d3
  1524.         addq.l    #3,d2
  1525.         addq.l    #3,d3
  1526.         moveq    #0,d0
  1527.         moveq    #0,d1
  1528.         move.l    grid_rp(a6),a1
  1529.  
  1530.         movem.w    d2-d3,-(sp)    ;save end coords
  1531.  
  1532.         CALLGRAF    RectFill
  1533.  
  1534.         move.l    grid_rp(a6),a1
  1535.         moveq    #RP_JAM1,d0
  1536.         CALLGRAF    SetDrMd
  1537.  
  1538.         move.l    grid_rp(a6),a1
  1539.         moveq    #0,d0
  1540.         CALLGRAF    SetAPen
  1541.  
  1542.         moveq    #2,d0
  1543.         moveq    #2,d1
  1544.         move.l    grid_rp(a6),a1
  1545.         CALLGRAF    Move
  1546.  
  1547.         movem.w    (sp),d0-d1
  1548.         subq.w    #2,d0
  1549.         moveq    #2,d1
  1550.         move.l    grid_rp(a6),a1
  1551.         CALLGRAF    Draw
  1552.  
  1553.         movem.w    (sp),d0-d1
  1554.         subq.w    #2,d0
  1555.         subq.w    #2,d1
  1556.         move.l    grid_rp(a6),a1
  1557.         CALLGRAF    Draw
  1558.  
  1559.         movem.w    (sp)+,d0-d1
  1560.         moveq    #2,d0
  1561.         subq.w    #2,d1
  1562.         move.l    grid_rp(a6),a1
  1563.         CALLGRAF    Draw
  1564.  
  1565.         moveq    #2,d0
  1566.         moveq    #2,d1
  1567.         move.l    grid_rp(a6),a1
  1568.         CALLGRAF    Draw
  1569.  
  1570.         move.w    grid_across(a6),d2    ;counter
  1571.         subq.w    #1,d2            ;1 less needed
  1572.         moveq    #SQ_X+1,d0        ;start coords
  1573.         moveq    #2,d1
  1574.         move.w    grid_down(a6),d3
  1575.         mulu    #SQ_Y,d3
  1576.         addq.w    #1,d3
  1577.         move.l    grid_rp(a6),a1
  1578.  
  1579. FW2_L3        movem.l    d0-d3/a1,-(sp)    ;save drawing parameters
  1580.         CALLGRAF    Move        ;set start drawing pos
  1581.         movem.l    (sp),d0-d3/a1    ;get parms back
  1582.         move.w    d3,d1
  1583.         CALLGRAF    Draw        ;now draw vertical line
  1584.         movem.l    (sp),d0-d3/a1
  1585.         addq.w    #1,d0        ;start 1 pixel along
  1586.         CALLGRAF    Move
  1587.         movem.l    (sp),d0-d3/a1
  1588.         move.w    d3,d1
  1589.         addq.w    #1,d0
  1590.         CALLGRAF    Draw        ;draw another vertical line
  1591.         movem.l    (sp)+,d0-d3/a1
  1592.         add.w    #SQ_X,d0        ;next position
  1593.         subq.w    #1,d2        ;done them all?
  1594.         bne.s    FW2_L3        ;back for more if not
  1595.  
  1596.         move.w    grid_down(a6),d2        ;counter
  1597.         subq.w    #1,d2            ;1 less needed
  1598.         moveq    #2,d0            ;start coords
  1599.         moveq    #SQ_Y+1,d1
  1600.         move.w    grid_across(a6),d3
  1601.         mulu    #SQ_Y,d3
  1602.         addq.w    #1,d3
  1603.         move.l    grid_rp(a6),a1
  1604.  
  1605. FW2_L4        movem.l    d0-d3/a1,-(sp)    ;save drawing parameters
  1606.         CALLGRAF    Move        ;set start drawing pos
  1607.         movem.l    (sp),d0-d3/a1    ;get parms back
  1608.         move.w    d3,d0
  1609.         CALLGRAF    Draw        ;now draw vertical line
  1610.         movem.l    (sp),d0-d3/a1
  1611.         addq.w    #1,d1        ;start 1 pixel down
  1612.         CALLGRAF    Move
  1613.         movem.l    (sp),d0-d3/a1
  1614.         move.w    d3,d0
  1615.         addq.w    #1,d1
  1616.         CALLGRAF    Draw        ;draw another vertical line
  1617.         movem.l    (sp)+,d0-d3/a1
  1618.         add.w    #SQ_Y,d1        ;next position
  1619.         subq.w    #1,d2        ;done them all?
  1620.         bne.s    FW2_L4        ;back for more if not
  1621.  
  1622.         bsr    DisplayGrid
  1623.  
  1624.         bsr    FreeText
  1625.  
  1626.         bsr    DisposeClueList
  1627.  
  1628.         bsr    InitUndo
  1629.  
  1630.         move.w    grid_across(a6),d0
  1631.         mulu    grid_down(a6),d0
  1632.  
  1633.         move.w    d0,WSCount(a6)    ;new white square count
  1634.         clr.w    SLCount(a6)    ;no more solutions entered
  1635.  
  1636. FW2_Done        rts
  1637.  
  1638.  
  1639. * ClearGrid(a6)
  1640. * a6 = ptr to main program variables
  1641. * remove ALL solutions from crossword grid
  1642.  
  1643. * d0-d7/a0-a2 corrupt
  1644.  
  1645.  
  1646. ClearGrid    btst    #1,applic_flag2(a6)    ;HELP on?
  1647.         beq.s    CG_ok            ;skip if not
  1648.  
  1649.         lea    Help_CG,a0    ;pop up help box
  1650.         moveq    #5,d0
  1651.         bsr    _PopUpQR
  1652.  
  1653.         beq.s    CG_Done        ;exit if NO hit
  1654.         bra.s    CG_DoNow        ;else execute
  1655.  
  1656. CG_ok        lea    CGWarn,a0    ;if no help, pop up
  1657.         lea    QRT_1(pc),a1    ;a warning QueryReq
  1658.         moveq    #5,d0
  1659.  
  1660.         move.l    a0,irt_tlist(a6)
  1661.         move.l    a1,irt_itext(a6)
  1662.         move.w    d0,irt_count(a6)
  1663.  
  1664.         bsr    DoQueryReq
  1665.  
  1666.         btst    #6,applic_flag2(a6)    ;YES gadget hit
  1667.         beq.s    CG_Done            ;skip if not
  1668.  
  1669. CG_DoNow        move.l    grid_array(a6),a0        ;ptr to chars grid
  1670.  
  1671.         move.w    grid_down(a6),d6        ;no of squares down
  1672.         bra.s    CG_a1
  1673.  
  1674. CG_l1        move.w    grid_across(a6),d7    ;no of squares across
  1675.         bra.s    CG_a2
  1676.  
  1677. CG_l2        move.w    (a0),d2        ;get whole data
  1678.         tst.b    d2        ;check black/white square
  1679.         beq.s    CG_b1        ;black so leave it
  1680.  
  1681.         move.b    #" ",d2        ;else set blank white square
  1682.         move.w    d2,(a0)        ;set grid byte
  1683.  
  1684.         movem.l    d6-d7/a0,-(sp)    ;save ptrs to grid etc
  1685.  
  1686.         move.w    grid_across(a6),d0
  1687.         sub.w    d7,d0        ;get across grid pos
  1688.         move.w    grid_down(a6),d1
  1689.         sub.w    d6,d1        ;and down grid pos
  1690.  
  1691.         bsr    SetSquare    ;set square
  1692.  
  1693.         movem.l    (sp)+,d6-d7/a0    ;recover ptrs to grid etc
  1694.  
  1695. CG_b1        addq.l    #2,a0        ;point to next grid square
  1696.  
  1697. CG_a2        dbra    d7,CG_l2
  1698.  
  1699. CG_a1        dbra    d6,CG_l1
  1700.  
  1701.         bsr    DisplayGrid
  1702.  
  1703.         bsr    InitUndo
  1704.  
  1705.         bsr    SetUnsolved
  1706.  
  1707.         clr.w    SLCount(a6)    ;no more solutions entered
  1708.  
  1709. CG_Done        rts
  1710.  
  1711.  
  1712. * SetSquare(a6,d0,d1,d2)
  1713. * a6 = ptr to main program variables
  1714. * d0 = across square #
  1715. * d1 = down square #
  1716. * d2 = char to set it to (0 for black square, " " for blank white square)
  1717.  
  1718. * Set grid square colour & pop in any char passed to the routine
  1719. * if it's a white square.
  1720.  
  1721. * Convention :
  1722.  
  1723. * 0        = black square
  1724. * nonzero    = white square + ASCII char value required
  1725. *          to display character in grid square
  1726.  
  1727. * Note:char in d2.b. High byte of d2.w contains the data for the
  1728. * horizontal & vertical bars for Daily Express Small Crossword type
  1729. * grid squares.
  1730.  
  1731. * d0-d6/a0-a1 corrupt
  1732.  
  1733.  
  1734. SetSquare    lea    sqtable(pc),a0    ;ptr to square data ptrs
  1735.  
  1736.         and.w    #$3FF,d2        ;ensure safe char parms
  1737.  
  1738.         moveq    #0,d3
  1739.         move.b    d2,d3
  1740.         sne    d3        ;either 0 or -1
  1741.         neg.b    d3        ;now either 0 or 1
  1742.         add.w    d3,d3        ;adjust to longword offset
  1743.         add.w    d3,d3
  1744.         lea    0(a0,d3.w),a0    ;get ptr to square data
  1745.  
  1746.         move.w    d2,d3
  1747.         lsr.w    #8,d3        ;get type 2 data
  1748.         add.w    d3,d3
  1749.         add.w    d3,d3        ;now 0,1,2 or 3
  1750.         lea    0(a0,d3.w),a0    ;get ptr to square data
  1751.         move.l    (a0),a0        ;and get ptr to bitmap to use
  1752.  
  1753.         subq.w    #1,d0
  1754.         mulu    #SQ_X,d0        ;convert to pixel pos
  1755.         addq.w    #2,d0
  1756.  
  1757.         subq.w    #1,d1
  1758.         mulu    #SQ_Y,d1        ;convert to pixel pos
  1759.         addq.w    #2,d1
  1760.  
  1761.         movem.w    d0-d2,-(sp)    ;save pixel pos etc
  1762.  
  1763.         move.w    d0,d2        ;destination x & y
  1764.         move.w    d1,d3        ;coordinates
  1765.         moveq    #0,d0        ;src x & y coordinates
  1766.         move.l    d0,d1
  1767.         move.l    grid_rp(a6),a1    ;ptr to dest rastport
  1768.         moveq    #10,d4        ;how much of BitMap to
  1769.         moveq    #10,d5        ;copy across
  1770.         move.w    #$CC,d6        ;minterm D=B
  1771.         CALLGRAF    BltBitMapRastPort    ;and transfer it
  1772.  
  1773.         CALLGRAF    WaitBlit        ;Do 2 calls just in case!
  1774.         CALLGRAF    WaitBlit
  1775.  
  1776.         movem.w    (sp)+,d0-d2    ;recover coords etc
  1777.  
  1778.         lea    itsquare(pc),a1
  1779.         move.l    12(a1),a2    ;ptr to itext
  1780.  
  1781.         move.b    d2,(a2)+        ;insert char
  1782.         clr.b    (a2)        ;ensure ASCIIZ text
  1783.  
  1784.         move.b    d2,d3        ;black or not?
  1785.         sne    d3        ;-1 if white, 0 if black
  1786.         neg.b    d3        ;1=white, 0=black
  1787.         ext.w    d3
  1788.         add.w    d3,WSCount(a6)    ;update white square count
  1789.  
  1790.         move.b    d2,d3
  1791.         seq    d3
  1792.         neg.b    d3        ;this time 1=black, 0=white
  1793.         ext.w    d3
  1794.         sub.w    d3,WSCount(a6)    ;update white square count
  1795.  
  1796.         tst.b    d2        ;check if black/non-black
  1797.         sne    d2        ;make 0 or -1 accordingly
  1798.         neg.b    d2        ;make 0 or 1
  1799.  
  1800.         move.b    d2,d3
  1801.         add.b    d2,d2        ;make 0 or 2
  1802.         add.b    d3,d2        ;make 0 or 3
  1803.  
  1804. ;        addq.b    #1,d2
  1805.  
  1806.         move.b    d2,(a1)        ;set fgnd colour to 0 or 3
  1807.         move.l    grid_rp(a6),a0    ;ptr to grid rastport
  1808.         CALLINT    PrintIText
  1809.  
  1810.         rts
  1811.  
  1812.  
  1813. * Blitter data for squares including bitmaps. Also table of pointers to
  1814. * the bitmaps for ease of access.
  1815.  
  1816.  
  1817. sqtable        dc.l    bsbmap        ;black square, type 0
  1818.         dc.l    wsbmap        ;white sq type 0 & 1
  1819.         dc.l    vbsbmap        ;type 1 vert bar square
  1820.         dc.l    hbsbmap        ;type 1 horiz bar square
  1821.         dc.l    bbsbmap        ;type 1 double bar square
  1822.  
  1823.  
  1824. bsbmap        dc.w    0,0
  1825.         dc.b    0,0
  1826.         dc.w    0
  1827.         dc.l    0,0
  1828.  
  1829. wsbmap        dc.w    0,0
  1830.         dc.b    0,0
  1831.         dc.w    0
  1832.         dc.l    0,0
  1833.  
  1834. vbsbmap        dc.w    0,0
  1835.         dc.b    0,0
  1836.         dc.w    0
  1837.         dc.l    0,0
  1838.  
  1839. hbsbmap        dc.w    0,0
  1840.         dc.b    0,0
  1841.         dc.w    0
  1842.         dc.l    0,0
  1843.  
  1844. bbsbmap        dc.w    0,0
  1845.         dc.b    0,0
  1846.         dc.w    0
  1847.         dc.l    0,0
  1848.  
  1849.  
  1850.  
  1851. * IntuiText data for squares
  1852.  
  1853.  
  1854. itsquare        dc.b    0,1        ;colour
  1855.         dc.b    RP_JAM1,0    ;mode
  1856.         dc.w    1,1        ;position
  1857.         dc.l    0        ;no font
  1858.         dc.l    itsqchar        ;ptr to chars
  1859.         dc.l    0        ;no more itexts
  1860.  
  1861. itsqchar        dc.b    " ",0        ;space char
  1862.         even
  1863.  
  1864.  
  1865. * DoEvent(a0,a5)
  1866. * a0 = ptr to user port to WAIT upon
  1867. * a5 = ptr to Event Handler Block
  1868. * do one read of the user port & handle events once.
  1869. * Note : does NOT handle one event at a time! Rather,
  1870. * checks one event sequence & processes that entire
  1871. * sequence. Written to allow multiple windows to have
  1872. * their own DoEvent() call by virtue of passing different
  1873. * UserPort pointers to it.
  1874.  
  1875. * d0/a0-a1 corrupt
  1876.  
  1877. * NON-MODIFIABLE.
  1878.  
  1879.  
  1880. DoEvent        move.l    a0,-(sp)
  1881.         CALLEXEC    WaitPort        ;Wait for port
  1882.         move.l    (sp)+,a0
  1883.  
  1884.         CALLEXEC    GetMsg        ;now get message
  1885.         move.l    d0,a1        ;here ascertain type
  1886.  
  1887.  
  1888. * Here goes code to handle such things as mouse handling in the
  1889. * absence of MENUVERIFY, and implementing MENUCANCEL if wanted.
  1890. * Don't forget to make the code save the message ptr if required!
  1891.  
  1892.  
  1893.         move.l    ehb_mousecode(a5),d0    ;code exists?
  1894.         beq.s    DoEvent_1        ;no-don't execute!
  1895.         move.l    d0,a0            ;get code pointer
  1896.         jsr    (a0)            ;& execute routine
  1897.  
  1898.  
  1899. * Now reply the message.
  1900.  
  1901.  
  1902. DoEvent_1    CALLEXEC    ReplyMsg        ;reply the message
  1903.  
  1904.  
  1905. * Now go execute the code required by the given IDCMP message.
  1906.  
  1907.  
  1908.         move.l    ehb_othercode(a5),d0    ;code exists?
  1909.         beq.s    DoEvent_2        ;no-don't execute
  1910.         move.l    d0,a0            ;get ptr
  1911.  
  1912.         move.l    ehb_IDCMPlist(a5),a1    ;IDCMP list ptr
  1913.         move.l    event_class(a6),d0    ;IDCMP received
  1914.         jsr    (a0)            ;do it
  1915.  
  1916. DoEvent_2    rts
  1917.  
  1918.  
  1919. * SelectEvent(d0,a1)
  1920. * d0 = IDCMP message received from somewhere else
  1921. * a1 = ptr to IDCMP list to use to decide what to do
  1922. * executes various routines based upon IDCMP message
  1923. * & IDCMP selection list.
  1924.  
  1925. * This will be the normal code choice for ehb_othercode in
  1926. * the Event Handler Block structure, but the way it has been
  1927. * written allows alternative ehb_othercode's to exist using
  1928. * this as a basis.
  1929.  
  1930. * d1/d2/a1 corrupt by this routine. OTHER CODE
  1931. * CALLED BY THIS ROUTINE MAY WRECK OTHER REGISTERS!
  1932.  
  1933. * NON-MODIFIABLE.
  1934.  
  1935.  
  1936. SelectEvent    movem.l    (a1)+,d1/d2    ;get flag, code pointer
  1937.         tst.l    d1        ;end of list?
  1938.         beq.s    SE_done        ;yes!-exit
  1939.         and.l    d0,d1        ;this IDCMP?
  1940.         beq.s    SE_1        ;no, skip
  1941.         movem.l    d0/a1,-(sp)    ;else save these
  1942.         move.l    d2,a1        ;get code pointer
  1943.         jsr    (a1)        ;& execute it
  1944.         movem.l    (sp)+,d0/a1    ;recover IDCMP msg & list ptr
  1945. SE_1        bra.s    SelectEvent    ;and do again
  1946.  
  1947. SE_done        rts
  1948.  
  1949.  
  1950. * AlterEvent(a1,a6)
  1951. * a1 = ptr to received IntuiMessage
  1952. * a6 = ptr to main program variables
  1953. * Do a GetIM() (see below) and then
  1954. * alter the message before reply if needed.
  1955.  
  1956. * d0-d1 corrupt
  1957.  
  1958. * MODIFIABLE.
  1959.  
  1960.  
  1961. AlterEvent    bsr.s    GetIM
  1962.  
  1963.         rts
  1964.  
  1965.  
  1966. * GetIM(a1,a6)
  1967. * a1 = ptr to received IntuiMessage
  1968. * a6 = ptr to main program variables
  1969. * Read the message & store in private variables
  1970. * d0/d1 corrupt
  1971.  
  1972. * NON-MODIFIABLE.
  1973.  
  1974.  
  1975. GetIM        move.l    im_class(a1),d0
  1976.         move.l    d0,event_class(a6)    ;IDCMP event class
  1977.         move.w    im_code(a1),d0
  1978.         move.w    d0,menu_id(a6)        ;menu ID selected
  1979.         move.w    im_qualifier(a1),d0
  1980.         move.w    d0,shift_stat(a6)
  1981.         move.l    im_iaddress(a1),d0
  1982.         move.l    d0,gadget_id(a6)        ;address of selected gadget
  1983.         move.w    im_mousex(a1),d0
  1984.         move.w    im_mousey(a1),d1
  1985.         move.w    d0,mouse_xpos(a6)
  1986.         move.w    d1,mouse_ypos(a6)
  1987.  
  1988.         rts
  1989.  
  1990.  
  1991. * DoMenus(a6)
  1992. * a6 = ptr to main program variables.
  1993. * handle Menu event. Relies on menu_id(a6)
  1994. * menu_list(a6) and menu_strip(a6) being
  1995. * properly conditioned.
  1996.  
  1997. * d0-d1/a0-a1 corrupt. NOTE: OTHER CODE CALLED BY THIS
  1998. * COULD TRASH OTHER REGISTERS TOO!
  1999.  
  2000. * NON-MODIFIABLE.
  2001.  
  2002.  
  2003. DoMenus        move.w    menu_id(a6),d0    ;initial MenuNumber
  2004.  
  2005. DM_1        move.l    menu_list(a6),a0    ;& list for this menu
  2006.  
  2007.         cmp.w    #MENUNULL,d0    ;no real selection?
  2008.         beq.s    DM_done        ;no, so exit cleanly.
  2009.  
  2010. * Here real menu selection made. Check which one in list.
  2011.  
  2012. DM_2        move.w    (a0)+,d1        ;get comparison MenuNumber
  2013.         move.l    (a0)+,a1        ;& routine to execute for it
  2014.  
  2015.         cmp.w    #MENUNULL,d1    ;end of list?
  2016.         beq.s    DM_done        ;yes, so exit cleanly.
  2017.  
  2018.         cmp.w    d1,d0        ;this menu selection?
  2019.         bne.s    DM_2        ;no, try another
  2020.  
  2021. * Here we've found the one we want. Save MenuNumber 
  2022. * then execute the routine.
  2023.  
  2024.         move.w    d0,-(sp)        ;save data
  2025.         jsr    (a1)        ;execute routine
  2026.  
  2027. * Now recover saved data, & obtain the NextSelect field. If not
  2028. * MENUNULL, process this one as well.
  2029.  
  2030.         moveq    #0,d0        ;ItemAddress() expects LONG!
  2031.         move.w    (sp)+,d0        ;temp. recover only
  2032.         move.l    menu_strip(a6),a0
  2033.         CALLINT    ItemAddress    ;point to MenuItem structure
  2034.         move.l    d0,a0
  2035.         move.w    mi_NextSelect(a0),d0    ;get NextSelect
  2036.         move.l    menu_list(a6),a0        ;and compare list
  2037.         bra.s    DM_1            ;and check again.
  2038.  
  2039. * Get here when finished!
  2040.  
  2041. DM_done        rts
  2042.  
  2043.  
  2044. * DoIGadget(a6)
  2045. * a6 = ptr to main variables
  2046.  
  2047. * Execute a GADGIMMEDIATE routine.
  2048.  
  2049. * Only uses gg_UserData.
  2050.  
  2051.  
  2052. DoIGadget    move.l    gadget_id(a6),d0        ;get gadget ID
  2053.         beq.s    DoneIG            ;not a real one
  2054.         move.l    d0,a0
  2055.         move.l    gg_UserData(a0),d0    ;get routine ptr
  2056.         beq.s    DoneIG            ;there isn't one
  2057.         move.l    d0,a0
  2058.         jmp    (a0)            ;else execute it
  2059. DoneIG        rts
  2060.  
  2061.  
  2062. * DoRGadget(a6)
  2063. * a6 = ptr to main variables
  2064.  
  2065. * Execute a RELVERIFY routine.
  2066.  
  2067. * Only uses gg_UserData+4.
  2068.  
  2069.  
  2070. DoRGadget    move.l    gadget_id(a6),d0        ;get gadget ID
  2071.         beq.s    DoneRG            ;not a real one
  2072.         move.l    d0,a0
  2073.         move.l    gg_UserData+4(a0),d0    ;get routine ptr
  2074.         beq.s    DoneRG            ;there isn't one
  2075.         move.l    d0,a0
  2076.         jmp    (a0)            ;else execute it
  2077. DoneRG        rts
  2078.  
  2079.  
  2080. * DoGadget(a6)
  2081. * a6 = ptr to main program variables
  2082. * execute a routine associated with a gadget.
  2083. * This routine checks the gg_userdata field
  2084. * first, & executes routine if present. If
  2085. * not, gets gg_GadgetID and uses as index into
  2086. * table of gadget jump addresses. If GadgetID
  2087. * is zero, routine exits. If both RELVERIFY
  2088. * and GADGIMMEDIATE set, and this routine is
  2089. * attached to both GADGETUP/GADGETDOWN IDCMP,
  2090. * then for a given gadget this routine will
  2091. * be executed twice.
  2092.  
  2093. * JMP (A0) assumes that each routine called ends
  2094. * in RTS. This RTS returns to caller of DoGadget().
  2095.  
  2096. * d0/a0/a1 corrupt
  2097.  
  2098. * NON-MODIFIABLE.
  2099.  
  2100.  
  2101. DoGadget        move.l    gadget_id(a6),d0    ;get gadget addr ptr
  2102.         beq.s    DG_Done        ;not a real one!
  2103.  
  2104.         move.l    d0,a0
  2105.         move.l    gadget_list(a6),a1    ;jump table list
  2106.  
  2107.         move.l    gg_UserData(a0),d0    ;get gg_userdata
  2108.         beq.s    DG_1            ;nonexistent so skip
  2109.  
  2110.         move.l    d0,a0        ;get execution addr
  2111.         jmp    (a0)        ;& execute it
  2112.  
  2113. DG_1        move.w    gg_GadgetID(a0),d0    ;get gg_GadgetID
  2114.         beq.s    DG_Done            ;nonexistent so skip
  2115.  
  2116.         ext.l    d0
  2117.         add.l    d0,d0
  2118.         add.l    d0,d0        ;longword index!
  2119.  
  2120.         move.l    0(a1,d0.l),d0    ;get execution address
  2121.         beq.s    DG_Done        ;invalid-quit now!
  2122.         move.l    d0,a0        ;else get execution addr
  2123.         jmp    (a0)        ;and do it!
  2124.  
  2125. DG_Done        rts
  2126.  
  2127.  
  2128. * DoMouseMove(a6)
  2129. * a6 = ptr to main program variables
  2130.  
  2131. * Handle mouse movement functions.
  2132.  
  2133. * d0-d2 corrupt
  2134.  
  2135.  
  2136. DoMouseMove    move.w    mp_across(a6),oldmpac(a6)    ;save old square
  2137.         move.w    mp_down(a6),oldmpdn(a6)    ;pointer posn's
  2138.  
  2139.         move.l    mw_handle(a6),a0    ;ptr to Window structure
  2140.  
  2141.         btst    #3,applic_flag1(a6)    ;picking a clue?
  2142.         bne.s    DMM_5            ;skip if so
  2143.  
  2144.         move.w    mouse_ypos(a6),d0    ;get mouse ptr vert posn
  2145.         cmp.w    #ON_MENU,d0    ;is it on menu bar?
  2146.         bcs.s    DMM_1        ;skip if it is
  2147.  
  2148. DMM_5        bset    #0,25(a0)    ;set RMBTRAP if not
  2149.         bra.s    DMM_2
  2150.  
  2151. DMM_1        bclr    #0,25(a0)    ;clear RMBTRAP if yes    
  2152.  
  2153. DMM_2        moveq    #0,d0        ;clear regs for later DIVU!
  2154.         move.l    d0,d1
  2155.         moveq    #-1,d2
  2156.  
  2157.         move.w    d2,mp_across(a6)    ;values for mouse ptr off
  2158.         move.w    d2,mp_down(a6)    ;crossword grid
  2159.  
  2160.         move.w    mouse_xpos(a6),d0    ;get mouse horiz position
  2161.         cmp.w    grid_hl(a6),d0    ;off left edge of grid?
  2162.         bcs    DMM_Done        ;yes, so exit NOW
  2163.  
  2164.         cmp.w    grid_hu(a6),d0    ;off right edge of grid?
  2165.         bhi    DMM_Done        ;yes, so exit NOW
  2166.  
  2167.         move.w    mouse_ypos(a6),d1    ;get mouse vert position
  2168.         cmp.w    grid_vl(a6),d1    ;off top edge of grid?
  2169.         bcs    DMM_Done        ;yes, so exit NOW
  2170.  
  2171.         cmp.w    grid_vu(a6),d1    ;off bottom edge of grid?
  2172.         bhi    DMM_Done
  2173.  
  2174.  
  2175. * Here compute which square is being addressed.
  2176.  
  2177.  
  2178.         sub.w    grid_hl(a6),d0
  2179.         divu    #SQ_X,d0
  2180.         add.w    grid_firstx(a6),d0
  2181.         move.w    d0,mp_across(a6)
  2182.  
  2183.         sub.w    grid_vl(a6),d1
  2184.         divu    #SQ_Y,d1
  2185.         add.w    grid_firsty(a6),d1
  2186.         move.w    d1,mp_down(a6)
  2187.  
  2188.         subq.w    #1,d1            ;vert square no -1
  2189.         mulu    grid_across(a6),d1    ;* no of squares across
  2190.         subq.w    #1,d0            ;horiz square -1
  2191.         ext.l    d0
  2192.         add.l    d1,d0            ;add on
  2193.         add.l    d0,d0            ;*2 for word offset
  2194.  
  2195.         move.l    d0,grid_offset(a6)
  2196.  
  2197.  
  2198. * if changing squares on normal crossword grid, change them.
  2199.  
  2200.  
  2201.         move.b    applic_flag1(a6),d0    ;get flags
  2202.         move.b    d0,d1
  2203.         btst    #3,d0            ;picking a clue?
  2204.         bne.s    DMM_3            ;skip if so
  2205.  
  2206.         and.b    #%11,d1            ;get mouse bits only
  2207.         beq.s    DMM_3            ;no mouse bits so skip
  2208.  
  2209.         move.w    mp_across(a6),d0        ;pointing to a
  2210.         cmp.w    oldmpac(a6),d0        ;new square?
  2211.         bne.s    DMM_4            ;continue if so
  2212.  
  2213.         move.w    mp_down(a6),d0
  2214.         cmp.w    oldmpdn(a6),d0
  2215.         beq.s    DMM_3            ;continue if so
  2216.  
  2217. DMM_4        move.l    grid_offset(a6),a0    ;ptr to current square
  2218.         move.l    a0,a1
  2219.         add.l    grid_array(a6),a0        ;ptr to grid element
  2220.         add.l    undo_array(a6),a1        ;ptr to undo element
  2221.  
  2222.         move.w    currsq(a6),d0    ;get square change value
  2223.         tst.b    d0        ;change to black square?
  2224.         beq.s    DMM_6        ;skip if so
  2225.         move.w    (a1),d1        ;get undo char
  2226.         tst.b    d1        ;accidentally black?
  2227.         bne.s    DMM_8
  2228.         move.b    #" ",d1        ;force blank white square
  2229. DMM_8        move.b    d1,d0        ;copy to square
  2230. ;        move.w    d0,(a1)        ;save in undo array
  2231.         move.w    d0,currsq(a6)    ;& enforce square change
  2232.         bra.s    DMM_7
  2233.  
  2234. DMM_6        move.w    (a0),(a1)    ;save current square
  2235.  
  2236. DMM_7        bsr    SquareChange    ;here change new square
  2237. ;        bra.s    DMM_3
  2238.  
  2239.  
  2240. * Here, display the square information.
  2241.  
  2242.  
  2243. DMM_3        lea    MPValues(pc),a0
  2244.         move.w    mp_across(a6),d0
  2245.         moveq    #2,d1
  2246.         bsr    ItoA
  2247.  
  2248.         move.l    mw_rastport(a6),a0
  2249.         lea    MPInfo(pc),a1
  2250.         move.w    #PG_RPOS+83,d0
  2251.         move.w    #PG_UPOS+7,d1
  2252.         CALLINT    PrintIText
  2253.  
  2254.         lea    MPValues(pc),a0
  2255.         move.w    mp_down(a6),d0
  2256.         moveq    #2,d1
  2257.         bsr    ItoA
  2258.  
  2259.         move.l    mw_rastport(a6),a0
  2260.         lea    MPInfo(pc),a1
  2261.         move.w    #PG_RPOS+83,d0
  2262.         move.w    #PG_UPOS+37,d1
  2263.         CALLINT    PrintIText
  2264.  
  2265.         bsr    DisplayGrid
  2266.  
  2267. DMM_Done        rts
  2268.  
  2269.  
  2270. MPInfo        dc.b    1,0
  2271.         dc.b    RP_JAM2,0
  2272.         dc.w    0,0
  2273.         dc.l    0        ;no font
  2274.         dc.l    MPValues        ;ptr to chars
  2275.         dc.l    0        ;no more itexts
  2276.  
  2277.  
  2278. MPValues        dc.b    "    ",0
  2279.         even
  2280.  
  2281.  
  2282.  
  2283. * DoMouseButton(a6)
  2284. * a6 = ptr to main program variables
  2285.  
  2286. * Handle mouse button functions.
  2287.  
  2288. * Performs the following:
  2289.  
  2290. * 1)    Check mouse position when button(s) pressed.
  2291.  
  2292. * 2)    If ptr on menu bar, exit-nothing else needs to be done.
  2293.  
  2294. * 3)    If ptr on grid, execute square changing code. See below for
  2295. *    modus operandi.
  2296.  
  2297. * 4)    If picking a clue for the clue editing or solution
  2298. *    editing functions, then don't do the square changing.
  2299.  
  2300. * Note also that this routine will abort if user has a requester up
  2301. * to prevent menu deadlocking.
  2302.  
  2303. * New for 1.2:undo array for remembering letters contained within
  2304. * grid squares if accidentally clicked upon.
  2305.  
  2306. * d0-d7/a0-a2 corrupt
  2307.  
  2308.  
  2309. DoMouseButton    tst.w    ReqCount(a6)    ;in a requester?
  2310.         bne    DoneMB        ;quit if so
  2311.  
  2312.         move.w    menu_id(a6),d0    ;check button status
  2313.         cmp.w    #SELECTDOWN,d0    ;LMB pressed?
  2314.         bne.s    DMB_1        ;skip if not
  2315.  
  2316.         or.b    #5,applic_flag1(a6)    ;set LM,C flags
  2317.  
  2318. ;        bset    #0,applic_flag1(a6)    ;set LM flag
  2319. ;        bset    #2,applic_flag1(a6)    ;and C flag
  2320.         bra.s    DMB_4
  2321.  
  2322. DMB_1        cmp.w    #SELECTUP,d0    ;LMB released?
  2323.         bne.s    DMB_2        ;skip if not
  2324.  
  2325.         move.b    #$FA,d0            ;clear LM,C flags
  2326.         tst.w    mp_across(a6)        ;on a grid square?
  2327.         bmi.s    DMB_1_1            ;skip if not
  2328.         bclr    #3,d0            ;else clear P flag
  2329.         
  2330. ;        and.b    #$F2,applic_flag1(a6)    ;clear LM,C,P flags
  2331.  
  2332. DMB_1_1        and.b    d0,applic_flag1(a6)    ;clear req'd flags
  2333.  
  2334. ;        bclr    #0,applic_flag1(a6)    ;clear LM flag
  2335. ;        bclr    #2,applic_flag1(a6)    ;and C flag
  2336.         bra.s    DMB_4
  2337.  
  2338. DMB_2        cmp.w    #MENUDOWN,d0    ;RMB pressed?
  2339.         bne.s    DMB_3        ;skip if not
  2340.  
  2341.         or.b    #6,applic_flag1(a6)    ;set RM,C flags
  2342.  
  2343. ;        bset    #1,applic_flag1(a6)    ;set RM flag
  2344. ;        bset    #2,applic_flag1(a6)    ;and C flag
  2345.         bra.s    DMB_4
  2346.  
  2347. DMB_3        cmp.w    #MENUUP,d0    ;RMB released?
  2348.         bne.s    DMB_4        ;skip if not
  2349.  
  2350.         move.b    #$F9,d0            ;clear LM,C flags
  2351.         tst.w    mp_across(a6)        ;on a grid square?
  2352.         bmi.s    DMB_3_1            ;skip if not
  2353.         bclr    #3,d0            ;else clear P flag
  2354.  
  2355. ;        and.b    #$F1,applic_flag1(a6)    ;clear RM,C,P flags
  2356.  
  2357. DMB_3_1        and.b    d0,applic_flag1(a6)    ;else clear req'd flags
  2358.  
  2359. ;        bclr    #1,applic_flag1(a6)    ;clear RM flag
  2360. ;        bclr    #2,applic_flag1(a6)    ;and C flag
  2361.  
  2362.  
  2363. * Here, check if picking a clue. If so, save the square
  2364. * position, and exit without doing anything more.
  2365.  
  2366.  
  2367. DMB_4        btst    #3,applic_flag1(a6)    ;picking a clue?
  2368.         beq.s    DMB_8            ;skip if not
  2369.  
  2370.         tst.w    mp_across(a6)        ;got a proper square?
  2371.         bmi    DoneMB            ;no, exit
  2372.  
  2373.         move.l    grid_offset(a6),a0
  2374.         add.l    grid_array(a6),a0
  2375.  
  2376.         tst.b    1(a0)            ;black square?
  2377.         beq    DoneMB            ;exit if so
  2378.  
  2379.         move.w    mp_across(a6),pick_hpos(a6)    ;else save
  2380.         move.w    mp_down(a6),pick_vpos(a6)        ;position
  2381.         move.l    grid_offset(a6),pick_offset(a6)
  2382.  
  2383.         bclr    #2,applic_flag1(a6)    ;Clear my C flag
  2384.  
  2385.         rts
  2386.  
  2387.  
  2388. * Here determine what sort of square change to make.
  2389. * Get current square type, and force a change. Store the
  2390. * change, and store the changed value in the main vars table.
  2391. * Use this in SquareChange() for future square changes when
  2392. * mouse buttons held down.
  2393.  
  2394.  
  2395. DMB_8        move.w    mp_across(a6),d0    ;on the grid?
  2396.         bmi    DoneMB        ;no so skip
  2397.  
  2398.         move.w    mp_down(a6),d1    ;on the grid?
  2399.         bmi    DoneMB        ;no so skip
  2400.  
  2401.         move.l    grid_offset(a6),a0
  2402.         move.l    a0,a1
  2403.         add.l    grid_array(a6),a0    ;get ptr to array word
  2404.         add.l    undo_array(a6),a1
  2405.  
  2406.         move.w    (a0),d2        ;get grid data
  2407.  
  2408.         tst.b    d2        ;black square?
  2409.         beq.s    DMB_yy        ;continue if so
  2410.  
  2411.         move.w    d2,(a1)        ;else save current state
  2412.  
  2413. ;        move.w    d2,savechar(a6)    ;else save char
  2414. ;        move.w    d0,save_h(a6)    ;and position
  2415. ;        move.w    d1,save_v(a6)
  2416.  
  2417. DMB_yy        move.b    applic_flag1(a6),d0    ;get LMB/RMB etc
  2418.         move.b    #%11,d1            ;temp mask for type 2
  2419.  
  2420.         btst    #6,d0        ;type 2 crossword?
  2421.         bne.s    DMB_5        ;skip if so
  2422.         clr.b    d1        ;else temp mask for type 1
  2423.  
  2424. DMB_5        and.b    d0,d1        ;create appropriate true mask
  2425.  
  2426.         lsl.w    #8,d1        ;if type 2 crossword, change
  2427.         eor.w    d1,d2        ;any type 2 bits, force type 1=0
  2428.  
  2429.         move.w    d2,d1        ;copy resulting square data
  2430.         btst    #6,d0        ;Type 2 crossword?
  2431.         beq.s    DMB_6        ;skip if not
  2432. ;        move.b    #" ",d1        ;else force white square
  2433.         move.w    (a1),d1        ;else force white & prev char
  2434.         bra.s    DMB_7        ;and make the change
  2435.  
  2436. DMB_6        tst.b    d1        ;state of low byte?
  2437.         seq    d1        ;if 0, make -1, if not 0, make 0
  2438.         tst.b    d1        ;result zero?
  2439.         beq.s    DMB_7        ;skip if so
  2440. ;        move.b    #" ",d1        ;else force blank white square
  2441.         move.w    (a1),d1        ;else force white & prev char
  2442.  
  2443.  
  2444. * At this point bits 8 & 9 of d2 contain type 2 bits. So now
  2445. * pop in any ASCII char data into bits 0-7.
  2446.  
  2447.  
  2448. DMB_7        move.b    d1,d2        ;create grid word
  2449.         move.w    d2,currsq(a6)    ;save the new square data
  2450.  
  2451. ;        move.w    (a0),d2        ;get original square data
  2452. ;        move.w    d2,(a1)        ;save in undo array
  2453.  
  2454.         btst    #2,d0        ;changing the square?
  2455.         beq.s    DoneMB        ;skip if not
  2456.  
  2457. ;        move.w    d0,save_h(a6)    ;save current pos
  2458. ;        move.w    d1,save_v(a6)
  2459.  
  2460. DMB_xx        move.w    (a0),d0        ;get current square data
  2461.  
  2462.         bsr    SquareChange    ;else force the square change
  2463.  
  2464.         bsr    DisplayGrid    ;show any results
  2465.  
  2466. DoneMB        rts            ;done!
  2467.  
  2468.  
  2469. * SquareChange(a6)
  2470. * a6 = ptr to main variables
  2471.  
  2472. * change state of currently pointed to square
  2473. * according to mouse button data.
  2474.  
  2475. * NEW for 1.2 : checks if editing allowed!
  2476.  
  2477. * d0-d3/a0-a1 corrupt
  2478.  
  2479.  
  2480. SquareChange    move.w    mp_across(a6),d0    ;get square row & col
  2481.         bmi.s    SCH_Done        ;exit if not on square!
  2482.         move.w    mp_down(a6),d1
  2483.         bmi.s    SCH_Done        ;ditto...
  2484.  
  2485.         tst.b    editon(a6)    ;editing allowed?
  2486.         bne.s    SCH_Done        ;skip if not
  2487.  
  2488.         move.l    grid_offset(a6),a0    ;get grid array element
  2489.         add.l    grid_array(a6),a0        ;address
  2490.  
  2491.         move.w    currsq(a6),d2
  2492.  
  2493. SCH_1        move.w    d2,(a0)        ;change array byte
  2494.  
  2495.         bsr    SetSquare    ;and alter square on grid
  2496.  
  2497. SCH_Done        rts
  2498.  
  2499.  
  2500. * AltMouseButton(a6)
  2501. * a6 = ptr to main program variables
  2502.  
  2503. * Alternative mouse button handler for within a requester.
  2504.  
  2505. * corrupt
  2506.  
  2507. AltMouseButton    and.b    #$FB,applic_flag1(a6)    ;clear C flag
  2508.  
  2509.         move.w    menu_id(a6),d0    ;check button status
  2510.         cmp.w    #SELECTDOWN,d0    ;LMB pressed?
  2511.         bne.s    AMB_1        ;skip if not
  2512.  
  2513.         or.b    #1,applic_flag1(a6)    ;set LM flag
  2514.         bra.s    AMB_4
  2515.  
  2516. AMB_1        cmp.w    #SELECTUP,d0    ;LMB released?
  2517.         bne.s    AMB_2        ;skip if not
  2518.  
  2519.         and.b    #$FE,applic_flag1(a6)    ;clear LM flag
  2520.         bra.s    AMB_4
  2521.  
  2522. AMB_2        cmp.w    #MENUDOWN,d0    ;RMB pressed?
  2523.         bne.s    AMB_3        ;skip if not
  2524.  
  2525.         or.b    #2,applic_flag1(a6)    ;set RM flag
  2526.         bra.s    AMB_4
  2527.  
  2528. AMB_3        cmp.w    #MENUUP,d0    ;RMB released?
  2529.         bne.s    AMB_4        ;skip if not
  2530.  
  2531.         and.b    #$FD,applic_flag1(a6)    ;clear LM flag
  2532.  
  2533. AMB_4        rts
  2534.  
  2535.  
  2536. * HandleRequest(a4)
  2537. * a4 = ptr to Requester handling block
  2538.  
  2539. * Handle all custom requesters except for DMRequesters,
  2540. * this routine kills off any VERIFY IDCMPs and then
  2541. * resets the original window IDCMP once ALL of the
  2542. * requesters are no longer active. Saves lots of
  2543. * needless hassle for other programmers using this
  2544. * code. Also sets RMBTRAP on the fly, preventing an
  2545. * accidental menu access. Note that it won't clear the
  2546. * RMBTRAP flag - that has to be done by the programmer
  2547. * if wanted once requester handling finished.
  2548.  
  2549. * NEVER CALL THIS WITHOUT INITIALISING THE rhb_ STRUCTURE
  2550. * BEFOREHAND!
  2551.  
  2552. * Note that this system maintains its integrity only if there
  2553. * is one window to condition. If several windows needed, then
  2554. * use this as a basis for a rewrite.
  2555.  
  2556. * Does not reactivate the window anymore-that's YOUR job!
  2557.  
  2558. * ASSUME ALL REGISTERS CORRUPT-OTHER CODE ACTIVATED
  2559. * BY THIS ROUTINE!
  2560.  
  2561. * MODIFIABLE
  2562.  
  2563.  
  2564. HandleRequest    move.l    a4,-(sp)        ;save for nested requesters!
  2565.  
  2566.         move.l    rhb_Window(a4),a0    ;prepare to recondition
  2567.         bset    #0,25(a0)    ;(set RMBTRAP also!)...
  2568.         move.l    #REQSET,d0    ;IDCMP for WAIT
  2569.         CALLINT    ModifyIDCMP
  2570.  
  2571.         bset    #7,applic_flag2(a6)    ;set requester on flag
  2572.  
  2573.         addq.w    #1,ReqCount(a6)        ;1 more active Req
  2574.  
  2575.         move.l    rhb_Requester(a4),a0    ;this requester
  2576.         move.l    rhb_Window(a4),a1        ;this window
  2577.         CALLINT    Request            ;set it up
  2578.  
  2579.  
  2580. * Here, wait for REQSET so that the PreCode functions properly (especially
  2581. * if it's a call to ActivateGadget()!!)
  2582.  
  2583.  
  2584. HReq_W1        move.l    rhb_EHB(a4),a5        ;get event block
  2585.         move.l    rhb_UserPort(a4),a0    ;& user port
  2586.         bsr    DoEvent            ;Event driven!
  2587.  
  2588.         btst    #7,applic_flag2(a6)    ;requester on?
  2589.         bne.s    HReq_W1            ;back if not
  2590.  
  2591.         move.l    rhb_Window(a4),a0    ;prepare to recondition
  2592.         move.l    rhb_IDCMP(a4),d0    ;IDCMPs
  2593.  
  2594.         bset    #0,25(a0)    ;set RMBTRAP also!
  2595.  
  2596.         move.l    #SIZEVERIFY,d1
  2597.         or.l    #MENUVERIFY,d1
  2598.         or.l    #REQVERIFY,d1
  2599.  
  2600.         not.l    d1
  2601.         and.l    d1,d0    ;kill off all VERIFYs!
  2602.  
  2603.         CALLINT    ModifyIDCMP
  2604.         bset    #7,applic_flag2(a6)    ;set requester on flag
  2605.  
  2606.         move.l    rhb_PreCode(a4),d0    ;any PreCode to run?
  2607.         beq.s    HReq_1            ;skip if not
  2608.  
  2609.         move.l    d0,a0        ;else prepare to run it
  2610.         jsr    (a0)        ;GO!
  2611.  
  2612. HReq_1        move.l    rhb_EHB(a4),a5        ;get event block
  2613.         move.l    rhb_UserPort(a4),a0    ;& user port
  2614.         bsr    DoEvent            ;Event driven!
  2615.  
  2616.         bset    #7,applic_flag2(a6)    ;left requester?
  2617.         bne.s    HReq_1            ;back if not
  2618.  
  2619.         move.l    (sp)+,a4        ;recover for nested calls!
  2620.  
  2621.         subq.w    #1,ReqCount(a6)        ;1 fewer req's active
  2622.         bne.s    HReq_2            ;skip if any still active
  2623.  
  2624.         move.l    rhb_Window(a4),a0        ;else restore the
  2625.         move.l    rhb_IDCMP(a4),d0        ;original IDCMP
  2626.  
  2627.         CALLINT    ModifyIDCMP
  2628.  
  2629.         bclr    #7,applic_flag2(a6)    ;signal no more reqs
  2630.  
  2631. ;        move.l    rhb_Window(a4),a0        ;and reactivate
  2632. ;        CALLINT    ActivateWindow        ;the window.
  2633.  
  2634. HReq_2        rts
  2635.  
  2636.  
  2637. * ItoA(a0,d0,d1)
  2638. * a0 = ptr to buffer into which to put the resulting string
  2639. * d0 = value to convert
  2640. * d1 = field width for resulting string
  2641.  
  2642. * d1-d3/a1 corrupt
  2643.  
  2644.  
  2645. ItoA        move.l    a0,a1        ;copy buffer ptr
  2646.  
  2647.         move.w    d1,d2        ;copy field width
  2648.         bra.s    ItoA_a1
  2649.  
  2650. ItoA_l1        move.b    #" ",(a1)+    ;space padding for string
  2651.  
  2652. ItoA_a1        dbra    d2,ItoA_l1
  2653.  
  2654.         clr.b    (a1)        ;and terminating EOS
  2655.  
  2656.         move.w    d0,d3        ;copy initial value
  2657.  
  2658. ItoA_l2        moveq    #0,d2
  2659.         move.w    d3,d2        ;ensure word sized operand
  2660.  
  2661.         divu    #10,d2        ;get trailing digit
  2662.         move.w    d2,d3        ;save quotient
  2663.         swap    d2
  2664.         add.b    #"0",d2        ;create ASCII digit
  2665.         move.b    d2,-(a1)        ;& save it
  2666.  
  2667.         subq.w    #1,d1        ;used entire fieldwidth?
  2668.         beq.s    ItoA_b1        ;exit if so
  2669.  
  2670.         tst.w    d3        ;quotient = 0?
  2671.         bne.s    ItoA_l2        ;back for more if not
  2672.  
  2673. ItoA_b1        rts            ;done
  2674.  
  2675.  
  2676. * MakeNewGrid(a6)
  2677. * a6 = ptr to main program variables
  2678.  
  2679. * Pop up the "New Crossword" requester & get details.
  2680. * Then if confirmed, create the new grid.
  2681.  
  2682. * ThisReq(a6) should point to an rhb_ structure (or at least
  2683. * an area of memory usable as one). The ENTIRE rhb_ structure
  2684. * is now initialised by this routine.
  2685.  
  2686. * ALL REGISTERS CORRUPT
  2687.  
  2688.  
  2689. MakeNewGrid    btst    #1,applic_flag2(a6)    ;HELP on?
  2690.         beq.s    MNG_ok            ;skip if not
  2691.  
  2692.         lea    Help_NG(pc),a0    ;do help
  2693.         moveq    #6,d0
  2694.         bsr    _PopUpQR
  2695.  
  2696.         beq    MNG_Done        ;and skip if aborted
  2697.  
  2698. MNG_ok        move.w    grid_across(a6),tmp_across(a6)    ;copy these
  2699.         move.w    grid_down(a6),tmp_down(a6)
  2700.  
  2701.  
  2702. * Now initialise rhb_ structure for HandleRequest() and TURN OFF the
  2703. * ReportMouse status of the window!
  2704.  
  2705.  
  2706.         move.l    ThisReq(a6),a4
  2707.  
  2708.         move.l    mw_handle(a6),rhb_Window(a4)
  2709.         move.l    mw_userport(a6),rhb_UserPort(a4)
  2710.         move.l    mw_IDCMP(a6),rhb_IDCMP(a4)
  2711.         lea    NewCWReq(pc),a0
  2712.         move.l    a0,rhb_Requester(a4)
  2713.         lea    ehb_req(pc),a0
  2714.         move.l    a0,rhb_EHB(a4)
  2715.  
  2716. ;        lea    SetHVPots1(pc),a0
  2717.         lea    InitNCGadgets(pc),a0
  2718.         move.l    a0,rhb_PreCode(a4)
  2719.  
  2720. ;        clr.l    rhb_PreCode(a4)
  2721.  
  2722.         bclr    #6,applic_flag2(a6)    ;CANCEL flag
  2723.  
  2724.         move.l    rhb_Window(a4),a0    ;this window
  2725.         moveq    #0,d0        ;FALSE
  2726. ;        exg    d0,a0        ;WARNING - change order!
  2727.         CALLINT    ReportMouse    ;and stop mouse reports!
  2728.  
  2729.         bsr    HandleRequest        ;do the requester
  2730.  
  2731.         btst    #6,applic_flag2(a6)    ;CANCEL gadget?
  2732.         beq.s    MNG_Done            ;skip if so
  2733.  
  2734.         bsr    ReplaceGrid    ;generate new grid
  2735.  
  2736. ;        bsr    FreeText        ;kill any previous
  2737.  
  2738. ;        bsr    DisposeClueList    ;clue list etc
  2739.  
  2740. MNG_Done        move.l    rhb_Window(a4),a0    ;this window
  2741.         moveq    #-1,d0        ;TRUE
  2742. ;        exg    d0,a0        ;WARNING - change order!
  2743.         CALLINT    ReportMouse    ;and re-enable mouse reports
  2744.  
  2745.         move.l    mw_handle(a6),a0    ;back to my window
  2746.         CALLINT    ActivateWindow
  2747.  
  2748.         rts
  2749.  
  2750.  
  2751. * SetHVPots1(a6)
  2752. * a6 = ptr to main program variables
  2753. * Sets the proportional gadgets coupled to the
  2754. * "New Crossword" requester and the string
  2755. * gadgets also.
  2756.  
  2757. * d0-d5/a0-a2 corrupt
  2758.  
  2759.  
  2760. SetHVPots1    lea    NC_HPot(pc),a0        ;ptr to HPot gadget
  2761.         move.l    mw_handle(a6),a1
  2762.         move.l    ThisReq(a6),a2
  2763.         move.l    rhb_Requester(a2),a2
  2764.  
  2765.         move.w    #FREEHORIZ+PROPBORDERLESS,d0    ;set flags
  2766.  
  2767.         moveq    #1,d3
  2768.         neg.w    d3
  2769.         divu    #MAXSQ_X,d3    ;create HorizBody
  2770.         move.w    d3,d1
  2771.         mulu    tmp_across(a6),d1    ;and HorizPot
  2772.         moveq    #-1,d2        ;Vertical values are
  2773.         moveq    #-1,d4        ;all -1
  2774.         moveq    #1,d5        ;refresh no other gadgets
  2775.         CALLINT    NewModifyProp
  2776.  
  2777.  
  2778.         lea    NC_VPot(pc),a0        ;ptr to HPot gadget
  2779.         move.l    mw_handle(a6),a1
  2780.         move.l    ThisReq(a6),a2
  2781.         move.l    rhb_Requester(a2),a2
  2782.  
  2783.         move.w    #FREEVERT+PROPBORDERLESS,d0    ;set flags
  2784.  
  2785.         moveq    #1,d4
  2786.         neg.w    d4
  2787.         divu    #MAXSQ_Y,d4    ;create VertBody
  2788.         move.w    d4,d2
  2789.         mulu    tmp_down(a6),d2    ;and VertPot
  2790.         neg.w    d2        ;inverted Y axis!
  2791.         moveq    #-1,d1        ;Horiz values are
  2792.         moveq    #-1,d3        ;all -1
  2793.         moveq    #1,d5        ;refresh no other gadgets
  2794.         CALLINT    NewModifyProp
  2795.  
  2796.         rts
  2797.  
  2798.  
  2799. * InitNCGadgets(a6)
  2800. * a6 = ptr to main program variables
  2801.  
  2802. * Initialise all of the "New Crossword" requester
  2803. * gadgets that need pre-initialisation.
  2804.  
  2805. * d0-d2/a0-a2/a5 corrupt
  2806.  
  2807.  
  2808. InitNCGadgets    bsr    SetHVPots1
  2809.         bsr    ResetAcross
  2810.         bsr    ResetDown
  2811.  
  2812.         rts
  2813.  
  2814.  
  2815. * ReplaceGrid(a6)
  2816. * a6 = ptr to main program variables
  2817.  
  2818. * Try to create new grid using tmp_ variables,
  2819. * and if it can be done, destroy the old one
  2820. * and replace the destroyed old one with the
  2821. * newly created one.
  2822.  
  2823. * d0-d2/a0-a1 corrupt
  2824.  
  2825.  
  2826. ReplaceGrid    move.l    #MEMF_VARS,d1
  2827.         CALLEXEC    AvailMem            ;how much memory left?
  2828.  
  2829.  
  2830. * Now compute how much memory will be free when we get rid of the
  2831. * current grid array & undo array.
  2832.  
  2833.  
  2834.         move.l    d0,d1            ;save amount left
  2835.         move.l    grid_bytes(a6),d0        ;amount in use
  2836.         add.l    d0,d0            ;by grid & undo
  2837.         add.l    d0,d1            ;total to be free
  2838.  
  2839.  
  2840. * Now calculate how much we'll need to allocate for the new grid
  2841. * array and undo array.
  2842.  
  2843.  
  2844.         move.w    tmp_across(a6),d0        ;no of squares across
  2845.         mulu    tmp_down(a6),d0        ;no of squares down
  2846.         add.l    d0,d0            ;array of m x n WORDS
  2847.         move.l    d0,tmp_size(a6)        ;save size
  2848.         add.l    d0,d0            ;2 of them!
  2849.  
  2850.  
  2851. * Now see if there is enough memory.
  2852.  
  2853.  
  2854.         cmp.l    d1,d0        ;enough memory?
  2855.         bls.s    RPG_Ok        ;skip if so
  2856.  
  2857.  
  2858. * Here, there isn't so report the problem and then leave.
  2859.  
  2860.  
  2861.         lea    IRT_1(pc),a1
  2862.         lea    NoNewGrid(pc),a0
  2863.         moveq    #8,d0
  2864.         move.l    a1,irt_itext(a6)
  2865.         move.l    a0,irt_tlist(a6)
  2866.         move.w    d0,irt_count(a6)
  2867.         bsr    LinkInfoText
  2868.         bsr    ShowInfoReq
  2869.  
  2870.         moveq    #0,d0        ;signal all's NOT well
  2871.  
  2872.         bra    RPG_1        ;and leave
  2873.  
  2874.  
  2875. * Here, we're all right. Get rid of old grid, old undo array,
  2876. * then allocate new ones. Do it all within Forbid()/Permit()
  2877. * to make sure another task doesn't steal my memory!
  2878.  
  2879.  
  2880. RPG_Ok        CALLEXEC    Forbid
  2881.  
  2882.         move.l    grid_array(a6),d0    ;got current grid?
  2883.         beq.s    RPG_b3        ;skip if not
  2884.         move.l    d0,a1
  2885.         move.l    grid_bytes(a6),d0
  2886.         CALLEXEC    FreeMem        ;release old grid
  2887.  
  2888. RPG_b3        move.l    undo_array(a6),d0    ;got undo array?
  2889.         beq.s    RPG_b4        ;skip if not
  2890.         move.l    d0,a1
  2891.         move.l    grid_bytes(a6),d0
  2892.         CALLEXEC    FreeMem        ;release old Undo
  2893.  
  2894. RPG_b4        move.l    tmp_size(a6),d0    ;first get new grid
  2895.         move.l    #MEMF_VARS,d1
  2896.         CALLEXEC    AllocMem
  2897.         move.l    d0,grid_array(a6)
  2898.  
  2899.         move.l    tmp_size(a6),d0    ;now get new undo
  2900.         move.l    #MEMF_VARS,d1
  2901.         CALLEXEC    AllocMem
  2902.         move.l    d0,undo_array(a6)
  2903.  
  2904.         move.w    tmp_across(a6),grid_across(a6)
  2905.         move.w    tmp_down(a6),grid_down(a6)
  2906.         move.l    tmp_size(a6),grid_bytes(a6)
  2907.  
  2908.         CALLEXEC    Permit
  2909.  
  2910.  
  2911. * Now set the coordinate limits for the mouse pointer. If mouse is in these
  2912. * limits, it's on the grid, otherwise it's off...
  2913.  
  2914.  
  2915.         move.w    #GRID_LEFT,d0    ;minimum LHS mouse coord
  2916.         move.w    d0,grid_hl(a6)    ;save it
  2917.         move.w    #SQ_X,d1
  2918.         move.w    grid_across(a6),d2
  2919.         cmp.w    #MAX_DISPX,d2
  2920.         bls.s    RPG_b1
  2921.         move.w    #MAX_DISPX,d2    ;constrain for oversize grid
  2922.  
  2923. RPG_b1        mulu    d2,d1
  2924.         add.w    d1,d0
  2925.         subq.w    #1,d0
  2926.         move.w    d0,grid_hu(a6)    ;maximum RHS mouse coord
  2927.  
  2928.         move.w    #GRID_UP,d0    ;minimum top mouse coord
  2929.         move.w    d0,grid_vl(a6)    ;save it
  2930.         move.w    #SQ_Y,d1
  2931.         move.w    grid_down(a6),d2
  2932.         cmp.w    #MAX_DISPY,d2
  2933.         bls.s    RPG_b2
  2934.         move.w    #MAX_DISPY,d2    ;constrain for oversize grid
  2935.  
  2936. RPG_b2        mulu    d2,d1
  2937.         add.w    d1,d0
  2938.         subq.w    #1,d0
  2939.         move.w    d0,grid_vu(a6)    ;maximum bottom mouse coord
  2940.  
  2941.  
  2942. * Now start changing the screen image for the new grid...
  2943.  
  2944.  
  2945.         move.l    mw_rastport(a6),a1    ;tmp change
  2946.         moveq    #0,d0            ;plotting pen
  2947.         CALLGRAF    SetAPen
  2948.  
  2949.         move.l    mw_rastport(a6),a1    ;erase image
  2950.         move.w    #GRID_LEFT,d0        ;from screen
  2951.         move.w    #GRID_UP,d1
  2952.         move.w    #GRID_LEFT+MAX_DISP_PX,d2
  2953.         move.w    #GRID_UP+MAX_DISP_PY,d3
  2954.         CALLGRAF    RectFill
  2955.  
  2956.         move.l    mw_rastport(a6),a1    ;recover original
  2957.         moveq    #4,d0            ;detail pen
  2958.         CALLGRAF    SetAPen
  2959.  
  2960.         move.l    grid_rp(a6),a1
  2961.         moveq    #1,d0
  2962.         CALLGRAF    SetRast        ;get rid of old grid image
  2963.  
  2964.         bsr    SetMainHVPots    ;set PropGadgets & TLC
  2965.  
  2966.         lea    NC_Type(pc),a0    ;get ptr to Type Gadget
  2967.  
  2968.         move.w    gg_Flags(a0),d0    ;get flags
  2969.  
  2970.         and.w    #SELECTED,d0    ;was it in the selected state?
  2971.         bne.s    RPG_2        ;yes it was, so Type 2 grid
  2972.  
  2973.         bclr    #6,applic_flag1(a6)    ;set Type 1 grid
  2974.         bsr    FillBlack2        ;as it says
  2975.  
  2976.         move.l    mw_handle(a6),a0
  2977.         CALLINT    ClearMenuStrip
  2978.  
  2979.         move.l    mw_handle(a6),a0        ;turn on the "Fill
  2980.         move.w    #1+0*32+0*2048+$F800,d0    ;Black" menu item
  2981.         CALLINT    OnMenu
  2982.  
  2983.         move.l    mw_handle(a6),a0
  2984.         move.l    menu_strip(a6),a1
  2985.         CALLINT    SetMenuStrip
  2986.  
  2987.         bra.s    RPG_1            ;and go display it
  2988.  
  2989. RPG_2        bset    #6,applic_flag1(a6)    ;set Type 2 grid
  2990.         bsr    FillWhite2        ;as it says
  2991.  
  2992.         move.l    mw_handle(a6),a0
  2993.         CALLINT    ClearMenuStrip
  2994.  
  2995.         move.l    mw_handle(a6),a0        ;turn off the "Fill
  2996.         move.w    #1+0*32+0*2048+$F800,d0    ;Black" menu item
  2997.         CALLINT    OffMenu
  2998.  
  2999.         move.l    mw_handle(a6),a0
  3000.         move.l    menu_strip(a6),a1
  3001.         CALLINT    SetMenuStrip
  3002.  
  3003.         moveq    #-1,d0        ;signal all IS well...
  3004.  
  3005. RPG_1        rts            ;and done.
  3006.  
  3007.  
  3008. * QuitCode(a6)
  3009. * a6 = ptr to main program variables
  3010. * signals end of application runtime
  3011.  
  3012. * NON-MODIFIABLE
  3013.  
  3014.  
  3015. QuitCode        lea    QRT_1(pc),a0    ;set up the text data
  3016.         lea    Quit_YN(pc),a1    ;for the query
  3017.         moveq    #3,d0        ;requester
  3018.  
  3019.         move.l    a0,irt_itext(a6)    ;put said data here
  3020.         move.l    a1,irt_tlist(a6)
  3021.         move.w    d0,irt_count(a6)
  3022.  
  3023.         bsr    DoQueryReq    ;does the lot in one go
  3024.  
  3025.         btst    #6,applic_flag2(a6)    ;pressed "YES" gadget?
  3026.         beq.s    QuitCode_1        ;skip if not
  3027.  
  3028.         bclr    #7,applic_flag1(a6)    ;else quit program
  3029.  
  3030. QuitCode_1    rts
  3031.  
  3032.  
  3033. * WaitForReq(a6)
  3034. * a6 = ptr to main program variables
  3035. * Exit wait loop of HandleRequest() when REQSET arrives!
  3036.  
  3037. * nothing corrupt
  3038.  
  3039.  
  3040. WaitForReq    bclr    #7,applic_flag2(a6)    ;exit req loop
  3041.         rts
  3042.  
  3043.  
  3044. * QuitReq(a6)
  3045. * a6 = ptr to main program variables
  3046. * signals end of current requester, with the
  3047. * CANCEL gadget pressed.
  3048.  
  3049. * NON-MODIFIABLE
  3050.  
  3051.  
  3052. QuitReq        bclr    #7,applic_flag2(a6)
  3053.         bclr    #6,applic_flag2(a6)
  3054.         rts
  3055.  
  3056.  
  3057. * LeaveReq(a6)
  3058. * a6 = ptr to main program variables
  3059. * signals end of current requester,
  3060. * with the SELECT/EXECUTE gadget pressed.
  3061.  
  3062.  
  3063. LeaveReq        bclr    #7,applic_flag2(a6)
  3064.         bset    #6,applic_flag2(a6)
  3065.         rts
  3066.  
  3067.  
  3068.  
  3069. * Here go IDCMP comparator lists for event handling.
  3070. * Each entry consists of:1 longword IDCMP spec, then
  3071. * 1 longword, address of routine to execute when this
  3072. * IDCMP message is received. Last longword 0 marks the
  3073. * end of the list.
  3074.  
  3075.  
  3076. IDCMPlist1    dc.l    GADGETDOWN,DoIGadget
  3077.         dc.l    GADGETUP,DoRGadget
  3078.         dc.l    MENUPICK,DoMenus
  3079.         dc.l    MOUSEMOVE,DoMouseMove
  3080.         dc.l    MOUSEBUTTONS,DoMouseButton
  3081.         dc.l    DISKINSERTED,InDrive
  3082.         dc.l    DISKREMOVED,OutDrive
  3083.         dc.l    RAWKEY,HandleKey
  3084.         dc.l    0
  3085.  
  3086.  
  3087. IDCMPlist2    dc.l    GADGETDOWN,DoIGadget
  3088.         dc.l    GADGETUP,DoRGadget
  3089.         dc.l    REQSET,WaitForReq
  3090.         dc.l    0
  3091.  
  3092. IDCMPlist3    dc.l    MOUSEMOVE,DG_Done
  3093.         dc.l    MOUSEBUTTONS,ExitInfo
  3094.         dc.l    REQSET,WaitForReq
  3095.         dc.l    0
  3096.  
  3097. IDCMPlist4    dc.l    GADGETDOWN,DoIGadget
  3098.         dc.l    GADGETUP,DoRGadget
  3099.         dc.l    DISKINSERTED,InDrive
  3100.         dc.l    DISKREMOVED,OutDrive
  3101.         dc.l    0
  3102.  
  3103.  
  3104.  
  3105. * Menu List for main window. Entry consists of:
  3106. * 1 word for MenuNumber for comparison,
  3107. * 1 longword for routine to execute,
  3108. * until MENUNULL at end of list.
  3109.  
  3110.  
  3111. menulist_1    dc.w    0+0*32+0*2048+$F800
  3112.         dc.l    DoDiscPanel
  3113.         dc.w    0+1*32+0*2048+$F800
  3114.         dc.l    MakeNewGrid
  3115.         dc.w    0+2*32+0*2048+$F800
  3116.         dc.l    QuitCode
  3117.  
  3118.         dc.w    1+0*32+0*2048+$F800
  3119.         dc.l    FillBlack2
  3120.         dc.w    1+1*32+0*2048+$F800
  3121.         dc.l    FillWhite2
  3122.         dc.w    1+2*32+0*2048+$F800
  3123.         dc.l    ClearGrid
  3124.  
  3125.         dc.w    2+0*32+0*2048+$F800
  3126.         dc.l    CreateClueList
  3127.         dc.w    2+1*32+0*2048+$F800
  3128.         dc.l    EditClue
  3129.         dc.w    2+2*32+0*2048+$F800
  3130.         dc.l    EraseClue
  3131.  
  3132.         dc.w    3+0*32+0*2048+$F800
  3133.         dc.l    Solve
  3134.         dc.w    3+1*32+0*2048+$F800
  3135.         dc.l    Rubout            ;SodOff
  3136.  
  3137.         dc.w    MENUNULL
  3138.  
  3139.  
  3140. * Gadget list for ID number dependent gadgets on main window.
  3141. * Consists of longword pointers to routines to execute.
  3142.  
  3143.  
  3144. gadgetlist1    dc.l    DG_Done
  3145.  
  3146.  
  3147. * Standard Event Handler Block for the main window.
  3148.  
  3149.  
  3150. ehb_std        dc.l    AlterEvent    ;do VERIFYs?
  3151.         dc.l    SelectEvent    ;normal OtherCode
  3152.         dc.l    IDCMPlist1    ;normal IDCMP list
  3153.  
  3154.  
  3155. * Event handler block for Requesters including QueryRequesters
  3156.  
  3157.  
  3158. ehb_req        dc.l    AlterEvent    ;normal MouseCode
  3159.         dc.l    SelectEvent    ;normal OtherCode
  3160.         dc.l    IDCMPlist2    ;requester IDCMP list
  3161.  
  3162.  
  3163. * Event handler block for InfoRequesters
  3164.  
  3165.  
  3166. ehb_info        dc.l    AlterEvent
  3167.         dc.l    SelectEvent
  3168.         dc.l    IDCMPlist3
  3169.  
  3170.  
  3171. * Event handler block for disc access panel.
  3172.  
  3173.  
  3174. ehb_dp        dc.l    AlterEvent    ;do VERIFYs?
  3175.         dc.l    SelectEvent    ;normal OtherCode
  3176.         dc.l    IDCMPlist4    ;normal IDCMP list
  3177.  
  3178.  
  3179. * Requester handling block. Usage:set rhb_Window, rhb_UserPort with
  3180. * values for given window. Set rhb_IDCMP with the normal IDCMP for
  3181. * the window, to be restored when all requesters are inactive.
  3182. * Put ptr to Requester structure in rhb_Requester.
  3183. * Then pass pointer to this block in a4 to HandleRequest().
  3184.  
  3185.  
  3186. ReqBlock        dc.l    0,0,0,0,0,0
  3187.  
  3188.  
  3189. * Topaz-80 font TextAttr structure
  3190.  
  3191.  
  3192. Topaz_80        dc.l    Topaz_80_name
  3193.         dc.w    8        ;height = 8 (TOPAZ_80)
  3194.         dc.b    0        ;no style flags
  3195.         dc.b    $01        ;ROM font
  3196.         even
  3197.  
  3198.  
  3199. * Clue List Header Block (not initialised)
  3200.  
  3201.  
  3202. CLHeader        ds.b    clh_sizeof
  3203.  
  3204.  
  3205. * Texts such as library names etc.
  3206.  
  3207.  
  3208. dos_name        dc.b    "dos.library",0
  3209.  
  3210. int_name        dc.b    "intuition.library",0
  3211.  
  3212. graf_name    dc.b    "graphics.library",0
  3213.  
  3214. Topaz_80_name    dc.b    "topaz.font",0
  3215.  
  3216.         even
  3217.  
  3218.  
  3219. * Various code files.
  3220.  
  3221.  
  3222.         include    SOURCE2:INCLUDES/CWReqHandler.i
  3223.  
  3224.         include    SOURCE2:INCLUDES/CWDiscHandler.i
  3225.  
  3226.         include    SOURCE2:INCLUDES/CWDiscButtons.i
  3227.  
  3228.         include    SOURCE2:INCLUDES/CWExtras.i
  3229.  
  3230.         include    SOURCE2:INCLUDES/CWClues.i
  3231.  
  3232.         include    SOURCE2:INCLUDES/CWInfoReq.i
  3233.  
  3234.         include    SOURCE2:INCLUDES/CWQueryReq.i
  3235.  
  3236.  
  3237.  
  3238. * Data structures include files
  3239.  
  3240.  
  3241.         include    SOURCE2:INCLUDES/CWMenus.i
  3242.  
  3243.         include    SOURCE2:INCLUDES/CWNewReq.i
  3244.  
  3245.         include    SOURCE2:INCLUDES/CWDiscReq.i
  3246.  
  3247.         include    SOURCE2:INCLUDES/CWSolutions.i
  3248.  
  3249.         include    SOURCE2:INCLUDES/CWHelpCode.i
  3250.  
  3251.         include    SOURCE2:INCLUDES/CWInfoTexts.i
  3252.  
  3253.         include    SOURCE2:INCLUDES/CWFormat.i
  3254.  
  3255.  
  3256. * Graphics images include files and CHIP memory graphics data
  3257.  
  3258.  
  3259.         section    graphics,DATA_C
  3260.  
  3261.  
  3262. * Custom pointer for CrossWord program, 16 x 15,
  3263. * displayed as main pointer throughout the program.
  3264.  
  3265.  
  3266. CWPointer    dc.w    $8050,$9000    ;control words (see ASPG)
  3267.  
  3268.         dc.w    $0008,$0036    ;sprite def (15 lines)
  3269.         dc.w    $0010,$006e
  3270.         dc.w    $0022,$00dc
  3271.         dc.w    $0044,$01ba
  3272.         dc.w    $0088,$0376
  3273.  
  3274.         dc.w    $0110,$06ec
  3275.         dc.w    $0220,$0dd8
  3276.         dc.w    $0440,$1bb0
  3277.         dc.w    $0880,$3760
  3278.         dc.w    $0100,$7ec0
  3279.  
  3280.         dc.w    $7200,$7d80
  3281.         dc.w    $f800,$ff00
  3282.         dc.w    $f800,$fe00
  3283.         dc.w    $3800,$fc00
  3284.         dc.w    $3000,$f000
  3285.  
  3286.         dc.w    $0000,$0000    ;last 2 words
  3287.  
  3288.  
  3289. * This sprite pointer is 16 x 49. It is the "Zzzz" pointer for
  3290. * this program, equivalent to DPaint's "Zz" or PowerWindows'
  3291. * "HANG" pointer, displaed when user should wait for something.
  3292.  
  3293.  
  3294. CWHangPtr    dc.w    0,0
  3295.  
  3296.         dc.w    $0000,$0000
  3297.         dc.w    $3800,$0088
  3298.         dc.w    $2400,$0088
  3299.         dc.w    $2400,$0088
  3300.         dc.w    $2400,$0088
  3301.         dc.w    $3800,$0088
  3302.         dc.w    $2000,$00A8
  3303.         dc.w    $2000,$00D8
  3304.         dc.w    $2000,$0088
  3305.         dc.w    $0000,$0000
  3306.  
  3307.         dc.w    $0020,$2000
  3308.         dc.w    $0050,$2000
  3309.         dc.w    $0088,$2000
  3310.         dc.w    $0088,$2000
  3311.         dc.w    $00F8,$2000
  3312.         dc.w    $0088,$2000
  3313.         dc.w    $0088,$3C00
  3314.         dc.w    $0000,$0000
  3315.         dc.w    $3C70,$3C70
  3316.         dc.w    $2020,$2020
  3317.  
  3318.         dc.w    $2020,$2020
  3319.         dc.w    $3820,$3820
  3320.         dc.w    $2020,$2020
  3321.         dc.w    $2020,$2020
  3322.         dc.w    $3C70,$3C70
  3323.         dc.w    $0000,$0000
  3324.         dc.w    $0800,$00F8
  3325.         dc.w    $1400,$0020
  3326.         dc.w    $2200,$0020
  3327.         dc.w    $2200,$0020
  3328.  
  3329.         dc.w    $3E00,$0020
  3330.         dc.w    $2200,$0020
  3331.         dc.w    $2200,$0020
  3332.         dc.w    $0000,$0000
  3333.         dc.w    $1C20,$1C20
  3334.         dc.w    $2220,$2220
  3335.         dc.w    $2020,$2020
  3336.         dc.w    $1C20,$1C20
  3337.         dc.w    $0220,$0220
  3338.         dc.w    $2200,$2200
  3339.  
  3340.         dc.w    $1C20,$1C20
  3341.         dc.w    $0000,$0000
  3342.         dc.w    $3C00,$0000
  3343.         dc.w    $2000,$0000
  3344.         dc.w    $2000,$0000
  3345.         dc.w    $3800,$0000
  3346.         dc.w    $2000,$0000
  3347.         dc.w    $2000,$0000
  3348.         dc.w    $3C00,$0000
  3349.  
  3350.         dc.w    $0000,$0000
  3351.  
  3352.  
  3353. * Data for squares as passed to BltBitMapRastPort().
  3354.  
  3355.  
  3356. bsquare        dc.w    %0000000000000000
  3357.         dc.w    %0000000000000000
  3358.         dc.w    %0000000000000000
  3359.         dc.w    %0000000000000000
  3360.         dc.w    %0000000000000000
  3361.         dc.w    %0000000000000000
  3362.         dc.w    %0000000000000000
  3363.         dc.w    %0000000000000000
  3364.         dc.w    %0000000000000000
  3365.         dc.w    %0000000000000000
  3366.  
  3367.  
  3368. wsquare        dc.w    %0000000000000000
  3369.         dc.w    %0111111110000000
  3370.         dc.w    %0111111110000000
  3371.         dc.w    %0111111110000000
  3372.         dc.w    %0111111110000000
  3373.         dc.w    %0111111110000000
  3374.         dc.w    %0111111110000000
  3375.         dc.w    %0111111110000000
  3376.         dc.w    %0111111110000000
  3377.         dc.w    %0000000000000000
  3378.  
  3379.  
  3380. vbsquare        dc.w    %0000000000000000
  3381.         dc.w    %0111111100000000
  3382.         dc.w    %0111111100000000
  3383.         dc.w    %0111111100000000
  3384.         dc.w    %0111111100000000
  3385.         dc.w    %0111111100000000
  3386.         dc.w    %0111111100000000
  3387.         dc.w    %0111111100000000
  3388.         dc.w    %0111111100000000
  3389.         dc.w    %0000000000000000
  3390.  
  3391.  
  3392. hbsquare        dc.w    %0000000000000000
  3393.         dc.w    %0111111110000000
  3394.         dc.w    %0111111110000000
  3395.         dc.w    %0111111110000000
  3396.         dc.w    %0111111110000000
  3397.         dc.w    %0111111110000000
  3398.         dc.w    %0111111110000000
  3399.         dc.w    %0111111110000000
  3400.         dc.w    %0000000000000000
  3401.         dc.w    %0000000000000000
  3402.  
  3403.  
  3404. bbsquare        dc.w    %0000000000000000
  3405.         dc.w    %0111111100000000
  3406.         dc.w    %0111111100000000
  3407.         dc.w    %0111111100000000
  3408.         dc.w    %0111111100000000
  3409.         dc.w    %0111111100000000
  3410.         dc.w    %0111111100000000
  3411.         dc.w    %0111111100000000
  3412.         dc.w    %0000000000000000
  3413.         dc.w    %0000000000000000
  3414.  
  3415.  
  3416.         include    SOURCE2:INCLUDES/CWImage1.i
  3417.         include    SOURCE2:INCLUDES/CWImage2.i
  3418.         include    SOURCE2:INCLUDES/CWImage3.i
  3419.  
  3420.  
  3421.  
  3422.  
  3423.  
  3424.